Skip to content

Commit 702fa5b

Browse files
crazyengRaj Balaebail
authored andcommitted
code refactor
1 parent 4404cb1 commit 702fa5b

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

wolframclient/cli/commands/benchmark.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from wolframclient.cli.utils import SimpleCommand
88
from wolframclient.deserializers import binary_deserialize
99
from wolframclient.language import wl
10+
from wolframclient.language.array import NumericArray, PackedArray
1011
from wolframclient.serializers import export
1112
from wolframclient.utils.debug import timed
1213
from wolframclient.utils.encoding import force_text
1314
from wolframclient.utils.functional import first
1415
from wolframclient.utils.importutils import safe_import_string_and_call
15-
from wolframclient.language.array import NumericArray, PackedArray
16+
1617

1718
def repeat(el, n=1):
1819
return tuple(el for _ in range(n))
@@ -30,7 +31,7 @@ def add_arguments(self, parser):
3031

3132
def expression_handler(self, complexity):
3233
return {
33-
'expr': {
34+
"expr": {
3435
"symbols": repeat(wl.Symbol, complexity),
3536
"strings": repeat("string", complexity),
3637
"bytes": repeat(b"bytes", complexity),
@@ -41,22 +42,26 @@ def expression_handler(self, complexity):
4142
"list": repeat([1, 2, 3], complexity),
4243
"functions": repeat(wl.Function(1, 2, 3), complexity),
4344
},
44-
'array': {
45-
'%s_%s' % (func.__name__, t): func(tuple(range(complexity * 100)), t)
45+
"array": {
46+
"%s_%s" % (func.__name__, t): func(tuple(range(complexity * 100)), t)
4647
for func in (PackedArray, NumericArray)
47-
for t in ('Integer64', 'Real64')
48-
}
48+
for t in ("Integer64", "Real64")
49+
},
4950
}
5051

51-
5252
def formatted_time(self, function, *args, **opts):
5353

5454
time = sum(first(timed(function)(*args, **opts)) for i in range(self.repetitions))
5555

5656
return "%.5f" % (time / self.repetitions)
5757

5858
def table_line(self, *iterable):
59-
self.print(*(force_text(c).ljust(i and self.col_size or self.title_size) for i, c in enumerate(iterable)))
59+
self.print(
60+
*(
61+
force_text(c).ljust(i and self.col_size or self.title_size)
62+
for i, c in enumerate(iterable)
63+
)
64+
)
6065

6166
def table_divider(self, length):
6267
self.print(*("-" * (i and self.col_size or self.title_size) for i in range(length)))
@@ -111,15 +116,15 @@ def report(self):
111116
)
112117
self.table_divider(len(self.complexity) + 1)
113118

114-
for key in ('expr', 'array'):
119+
for key in ("expr", "array"):
115120
for label, export_format, opts in (
116121
("wl", "wl", dict()),
117122
("wxf", "wxf", dict()),
118123
("wxf zip", "wxf", dict(compress=True)),
119124
):
120-
if key == 'expr' or (key == 'array' and not label == 'wl'):
125+
if key == "expr" or (key == "array" and not label == "wl"):
121126
self.table_line(
122-
key == 'expr' and label or '%s %s' % (label, key),
127+
key == "expr" and label or "%s %s" % (label, key),
123128
*(
124129
self.formatted_time(
125130
export,

0 commit comments

Comments
 (0)