66import tempfile
77
88from wolframclient .cli .utils import SimpleCommand
9+ from wolframclient .deserializers import binary_deserialize
910from wolframclient .language import wl
1011from wolframclient .serializers import export
1112from wolframclient .utils .debug import timed
@@ -39,13 +40,9 @@ def complexity_handler(self, complexity):
3940 "functions" : repeat (wl .Function (1 , 2 , 3 ), complexity ),
4041 }
4142
42- @timed
43- def export (self , * args , ** opts ):
44- return export (* args , ** opts )
43+ def formatted_time (self , function , * args , ** opts ):
4544
46- def formatted_time (self , * args , ** opts ):
47-
48- time = sum (first (self .export (* args , ** opts )) for i in range (self .repetitions ))
45+ time = sum (first (timed (function )(* args , ** opts )) for i in range (self .repetitions ))
4946
5047 return "%.5f" % (time / self .repetitions )
5148
@@ -55,27 +52,50 @@ def table_line(self, *iterable):
5552 def table_divider (self , length ):
5653 self .print (* ("-" * self .col_size for i in range (length )))
5754
55+ def stream_generators (self , path ):
56+ yield "Memory" , lambda complexity , export_format , path = path : None
57+ yield "File" , lambda complexity , export_format , path = path : os .path .join (
58+ path , "benchmark-test-%s.%s" % (force_text (complexity ).zfill (7 ), export_format )
59+ )
60+
5861 def report (self ):
5962
6063 path = tempfile .gettempdir ()
6164
6265 benchmarks = [(c , self .complexity_handler (c )) for c in self .complexity ]
6366
64- self .print ("dumping results in" , path )
67+ self .table_line ("dumping results in %s" % path )
68+ self .table_line ()
6569
6670 # running export to do all lazy loadings
6771 export (1 )
6872
69- for title , stream_generator in (
70- ("Memory" , lambda complexity : None ),
71- (
72- "File" ,
73- lambda complexity : os .path .join (
74- path ,
75- "benchmark-test-%s.%s" % (force_text (complexity ).zfill (7 ), export_format ),
76- ),
77- ),
78- ):
73+ self .table_line ("* Binary deserialize" )
74+ self .table_line ()
75+
76+ self .table_line (
77+ "Memory" , * (force_text (c ).ljust (self .col_size ) for c in self .complexity )
78+ )
79+ self .table_divider (len (self .complexity ) + 1 )
80+
81+ for label , opts in (("wxf" , dict ()), ("wxf zip" , dict (compress = True ))):
82+
83+ self .table_line (
84+ label ,
85+ * (
86+ self .formatted_time (
87+ binary_deserialize , export (expr , target_format = "wxf" , ** opts )
88+ )
89+ for complexity , expr in benchmarks
90+ )
91+ )
92+
93+ self .table_line ()
94+
95+ self .table_line ("* Export" )
96+ self .table_line ()
97+
98+ for title , stream_generator in self .stream_generators (path ):
7999
80100 self .table_line (
81101 title , * (force_text (c ).ljust (self .col_size ) for c in self .complexity )
@@ -91,8 +111,9 @@ def report(self):
91111 label ,
92112 * (
93113 self .formatted_time (
114+ export ,
94115 expr ,
95- stream = stream_generator (complexity ),
116+ stream = stream_generator (complexity , export_format ),
96117 target_format = export_format ,
97118 ** opts
98119 )
@@ -102,8 +123,6 @@ def report(self):
102123
103124 self .table_line ()
104125
105- self .table_line ()
106-
107126 def handle (self , profile , ** opts ):
108127 if profile :
109128 cProfile .runctx ("report()" , {"report" : self .report }, {})
0 commit comments