Skip to content

Commit 336b96e

Browse files
committed
[GR-23651] Resize pickle benchmarks.
PullRequest: graalpython/1042
2 parents 7fa1cfb + 67789c9 commit 336b96e

File tree

9 files changed

+83
-36
lines changed

9 files changed

+83
-36
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

graalpython/com.oracle.graal.python.benchmarks/python/micro/pickle_bench.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ def get_setup(module, name):
5151
# this is needed in order to unpickle the funcs references ...
5252
sys.path.append(os.path.split(__file__)[0])
5353

54-
def __setup__():
54+
def __setup__(multiplier):
5555
global DATA, dumps, loads
5656
dumps, loads = get_pickler(module)
57-
DATA = get_data(name)
57+
DATA = get_data(name) * multiplier
5858
return __setup__
5959

6060

61-
def __process_args__():
62-
pass
61+
def __process_args__(multiplier):
62+
return int(multiplier),
6363

6464

65-
def __teardown__():
65+
def __teardown__(multiplier):
6666
pass
6767

6868

69-
def __benchmark__():
69+
def __benchmark__(multiplier):
7070
dumped = [dumps(s) for s in DATA]
7171
loaded = [loads(b) for b in dumped]
7272
print("loaded DATA are the same as dumped DATA: ", loaded == DATA)

graalpython/com.oracle.graal.python.benchmarks/python/micro/pickle_gen_data.py

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,81 @@
4545
MOD_DIR = os.path.abspath(os.path.split(__file__)[0])
4646

4747

48-
def gen_dics(size=500, size_min=10, size_max=100):
49-
DATA = [random_dict(random.randint(size_min, size_max)) for _ in range(size)]
48+
def gen_dics(size=500, size_min=10, size_max=100, strings=None):
49+
print(">>>> gen {} dicts ...".format(size))
50+
DATA = []
51+
for i in range(size):
52+
if i % 10 == 0:
53+
print(".", end="", flush=True)
54+
DATA.append(random_dict(random.randint(size_min, size_max), strings=strings))
55+
print("\npickling dicts ... ")
5056
with open(os.path.join(MOD_DIR, "dicts.pickle"), "w+b") as FILE:
5157
pickle.dump(DATA, FILE)
58+
print("done")
5259

5360

54-
def gen_funcs(size=500):
55-
DATA = [random_func() for _ in range(size)]
61+
def gen_funcs(size=1000):
62+
print(">>>> gen {} funcs ...".format(size))
63+
DATA = []
64+
for i in range(size):
65+
if i % 100 == 0:
66+
print(".", end="", flush=True)
67+
DATA.append(random_func())
68+
print("\npickling funcs ...")
5669
with open(os.path.join(MOD_DIR, "funcs.pickle"), "w+b") as FILE:
5770
pickle.dump(DATA, FILE)
71+
print("done")
5872

5973

60-
def gen_lists(size=500, size_min=10, size_max=100):
61-
DATA = [random_list(random.randint(size_min, size_max)) for _ in range(size)]
74+
def gen_lists(size=500, size_min=10, size_max=100, strings=None):
75+
print(">>>> gen {} lists ...".format(size))
76+
DATA = []
77+
for i in range(size):
78+
if i % 100 == 0:
79+
print(".", end="", flush=True)
80+
DATA.append(random_list(random.randint(size_min, size_max), strings=strings))
81+
print("\npickling lists ...")
6282
with open(os.path.join(MOD_DIR, "lists.pickle"), "w+b") as FILE:
6383
pickle.dump(DATA, FILE)
84+
print("done")
6485

6586

6687
def gen_objects(size=500):
67-
DATA = [random_instance() for _ in range(size)]
88+
print(">>>> gen {} objects ...".format(size))
89+
DATA = []
90+
for i in range(size):
91+
if i % 100 == 0:
92+
print(".", end="", flush=True)
93+
DATA.append(random_instance())
94+
print("\npickling objects ...")
6895
with open(os.path.join(MOD_DIR, "objects.pickle"), "w+b") as FILE:
6996
pickle.dump(DATA, FILE)
97+
print("done")
7098

7199

72100
def gen_strings(size=10000, size_min=10, size_max=1000):
73-
DATA = [random_string(random.randint(size_min, size_max)) for _ in range(size)]
74-
with open(os.path.join(MOD_DIR, "strings.pickle"), "w+b") as FILE:
75-
pickle.dump(DATA, FILE)
101+
DATA = get_data("strings")
102+
if DATA and len(DATA) >= size:
103+
print("strings fixture is already generated, reusing ... ")
104+
DATA = DATA[:size]
105+
else:
106+
print(">>>> gen {} strings ...".format(size))
107+
DATA = []
108+
for i in range(size):
109+
if i % 1000 == 0:
110+
print(".", end="", flush=True)
111+
DATA.append(random_string(random.randint(size_min, size_max)))
112+
113+
print("\npickling strings ...")
114+
with open(os.path.join(MOD_DIR, "strings.pickle"), "w+b") as FILE:
115+
pickle.dump(DATA, FILE)
116+
print("done")
117+
return DATA
76118

77119

78120
if __name__ == '__main__':
79-
print(">>>> gen dicts ...")
80-
gen_dics()
81-
print(">>>> gen funcs ...")
121+
strings = gen_strings()
122+
gen_dics(strings=strings)
82123
gen_funcs()
83-
print(">>>> gen lists ...")
84-
gen_lists()
85-
print(">>>> gen objects ...")
124+
gen_lists(strings=strings)
86125
gen_objects()
87-
print(">>>> gen strings ...")
88-
gen_strings()

graalpython/com.oracle.graal.python.benchmarks/python/micro/pickle_utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,20 @@ def random_string(size):
6262
return ''.join([random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(size)])
6363

6464

65-
def random_list(size):
65+
def random_list(size, strings=None):
6666
def elem():
6767
t = random.randint(0, 2)
6868
if t == 0:
6969
return random.randint(0, 10000000000)
7070
elif t == 1:
7171
return float(random.randint(0, 10000000000))
72+
elif strings is not None:
73+
return strings[random.randint(0, len(strings))-1]
7274
return random_string(random.randint(100, 1000))
7375
return [elem() for _ in range(size)]
7476

7577

76-
def random_dict(size, ints_only=False):
78+
def random_dict(size, ints_only=False, strings=None):
7779
def elem():
7880
if ints_only:
7981
return random.randint(0, 10000000000)
@@ -83,6 +85,8 @@ def elem():
8385
return random.randint(0, 10000000000)
8486
elif t == 1:
8587
return float(random.randint(0, 10000000000))
88+
elif strings is not None:
89+
return strings[random.randint(0, len(strings)-1)]
8690
return random_string(random.randint(100, 1000))
8791
return {'key_'+str(random.randint(0, 1000000000)): elem() for _ in range(size)}
8892

@@ -115,8 +119,11 @@ def random_func():
115119

116120

117121
def get_data(name):
118-
file_name = "{}.pickle".format(name)
119-
file_name = os.path.abspath(os.path.join(os.path.split(__file__)[0], file_name))
120-
print(">>> loading {} data file ... ".format(file_name))
121-
with open(file_name, "r+b") as FILE:
122-
return pickle.load(FILE)
122+
try:
123+
file_name = "{}.pickle".format(name)
124+
file_name = os.path.abspath(os.path.join(os.path.split(__file__)[0], file_name))
125+
print(">>> loading {} data file ... ".format(file_name))
126+
with open(file_name, "r+b") as FILE:
127+
return pickle.load(FILE)
128+
except:
129+
return None
Binary file not shown.

mx.graalpython/mx_graalpython_bench_param.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
#
4545
# ----------------------------------------------------------------------------------------------------------------------
4646
# the argument list contains both the harness and benchmark args
47+
ITER_50 = ['-i', '50']
48+
ITER_35 = ['-i', '35']
4749
ITER_25 = ['-i', '25']
50+
ITER_20 = ['-i', '20']
4851
ITER_15 = ['-i', '15']
4952
ITER_10 = ['-i', '10']
5053

@@ -100,11 +103,11 @@
100103

101104
def _pickling_benchmarks(module='pickle'):
102105
return {
103-
'{}-strings'.format(module): ITER_10,
104-
'{}-lists'.format(module): ITER_10,
105-
'{}-dicts'.format(module): ITER_10,
106-
'{}-objects'.format(module): ITER_10,
107-
'{}-funcs'.format(module): ITER_10,
106+
'{}-strings'.format(module): ITER_35 + ['40'],
107+
'{}-lists'.format(module): ITER_35 + ['20'],
108+
'{}-dicts'.format(module): ITER_35 + ['10'],
109+
'{}-objects'.format(module): ITER_35 + ['300'],
110+
'{}-funcs'.format(module): ITER_35 + ['400'],
108111
}
109112

110113

0 commit comments

Comments
 (0)