klongpy 0.6.9__py3-none-any.whl → 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. klongpy/__init__.py +19 -1
  2. klongpy/adverbs.py +5 -5
  3. klongpy/autograd.py +308 -0
  4. klongpy/backend.py +167 -99
  5. klongpy/backends/__init__.py +94 -0
  6. klongpy/backends/base.py +320 -0
  7. klongpy/backends/numpy_backend.py +122 -0
  8. klongpy/backends/torch_backend.py +995 -0
  9. klongpy-0.6.9.data/scripts/kgpy → klongpy/cli.py +65 -88
  10. klongpy/core.py +228 -108
  11. klongpy/db/sys_fn_db.py +4 -3
  12. klongpy/dyads.py +159 -28
  13. klongpy/interpreter.py +31 -3
  14. klongpy/monads.py +39 -3
  15. klongpy/repl.py +21 -3
  16. klongpy/sys_fn.py +128 -17
  17. klongpy/sys_fn_autograd.py +290 -0
  18. klongpy/sys_fn_ipc.py +18 -6
  19. klongpy/sys_fn_timer.py +13 -3
  20. klongpy/web/sys_fn_web.py +14 -4
  21. klongpy-0.7.0.dist-info/METADATA +493 -0
  22. klongpy-0.7.0.dist-info/RECORD +48 -0
  23. {klongpy-0.6.9.dist-info → klongpy-0.7.0.dist-info}/WHEEL +1 -1
  24. klongpy-0.7.0.dist-info/entry_points.txt +2 -0
  25. {klongpy-0.6.9.dist-info → klongpy-0.7.0.dist-info}/top_level.txt +0 -1
  26. klongpy-0.6.9.dist-info/METADATA +0 -448
  27. klongpy-0.6.9.dist-info/RECORD +0 -77
  28. tests/__init__.py +0 -6
  29. tests/gen_join_over.py +0 -119
  30. tests/gen_py_suite.py +0 -77
  31. tests/gen_test_fn.py +0 -259
  32. tests/perf_async.py +0 -25
  33. tests/perf_avg.py +0 -18
  34. tests/perf_duckdb.py +0 -32
  35. tests/perf_gen.py +0 -38
  36. tests/perf_ipc_overhead.py +0 -34
  37. tests/perf_join.py +0 -53
  38. tests/perf_load.py +0 -17
  39. tests/perf_prog.py +0 -18
  40. tests/perf_serdes.py +0 -52
  41. tests/perf_sys_fn_db.py +0 -263
  42. tests/perf_vector.py +0 -40
  43. tests/test_accel.py +0 -227
  44. tests/test_df_cache.py +0 -85
  45. tests/test_eval_monad_list.py +0 -34
  46. tests/test_examples.py +0 -64
  47. tests/test_extra_suite.py +0 -382
  48. tests/test_file_cache.py +0 -185
  49. tests/test_interop.py +0 -180
  50. tests/test_kg_asarray.py +0 -94
  51. tests/test_kgtests.py +0 -65
  52. tests/test_known_bugs.py +0 -206
  53. tests/test_prog.py +0 -107
  54. tests/test_reshape_strings.py +0 -33
  55. tests/test_suite.py +0 -1480
  56. tests/test_suite_file.py +0 -153
  57. tests/test_sys_fn.py +0 -420
  58. tests/test_sys_fn_db.py +0 -88
  59. tests/test_sys_fn_ipc.py +0 -587
  60. tests/test_sys_fn_timer.py +0 -133
  61. tests/test_sys_fn_web.py +0 -50
  62. tests/test_util.py +0 -233
  63. tests/utils.py +0 -126
  64. {klongpy-0.6.9.dist-info → klongpy-0.7.0.dist-info}/licenses/LICENSE +0 -0
tests/gen_py_suite.py DELETED
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- import re
4
-
5
- back_slash_re = re.compile('\\[0-9"]')
6
-
7
- def quote_expr(s):
8
- s = re.sub(r'(\\[0-9"])', r'\\\1', s)
9
- # if '\\"' in s:
10
- # s = s.replace('\\"','\\\\"')
11
- if '"' in s and "'" in s:
12
- s = s.replace("'", "\\'")
13
- elif "'" in s:
14
- return f'"{s}"'
15
- # if '\"\"\"' in s:
16
- # s = s.replace('\"\"\"', '""\\"')
17
- return f"'{s}'"
18
-
19
- def get_tests():
20
- have_interp = False
21
- in_header = True
22
- test_names = set()
23
- with open("kgtests/language/test_suite.kg", "r") as f:
24
- for s in f:
25
- s = s.strip()
26
- if in_header:
27
- if s == ':" Atom "':
28
- in_header = False
29
- else:
30
- continue
31
- if len(s) == 0 or s == ':[err;[];.p("ok!")]':
32
- continue
33
- if s.startswith(":\""):
34
- have_interp = False
35
- if s.startswith(":\"Klong test suite"):
36
- continue
37
- x = s[2:-1].strip()
38
- name = x.lower().replace(" ","_").replace('-','_').replace('/','_').replace(":", "_")
39
- if name in test_names:
40
- name = name + "_2" # only one collision in suite
41
- test_names.add(name)
42
- print()
43
- print(f" def test_{name}(self):")
44
- continue
45
- if s.startswith("t("):
46
- p = [x.strip() for x in s[2:-1].split(';')][1:]
47
- if len(p) == 2:
48
- print(f" self.assert_eval_cmp({quote_expr(p[0])}, {quote_expr(p[1])}{', klong=klong' if have_interp else ''})")
49
- else:
50
- print(f" self.assert_eval_test({quote_expr(s)}{', klong=klong' if have_interp else ''} )")
51
- else:
52
- if not have_interp:
53
- have_interp = True
54
- print(f" klong = create_test_klong()")
55
- print(f" klong({quote_expr(s)})")
56
-
57
-
58
- if __name__ == '__main__':
59
- print("""import unittest
60
- from klongpy import KlongInterpreter
61
- from utils import *
62
-
63
- #
64
- # DO NOT MODIFY: this file generated by gen_py_suite.py
65
- #
66
- class TestCoreSuite(unittest.TestCase):
67
-
68
- def assert_eval_cmp(self, a, b, klong=None):
69
- self.assertTrue(eval_cmp(a, b, klong=klong))
70
-
71
- def assert_eval_test(self, a, klong=None):
72
- self.assertTrue(eval_test(a, klong=klong))""")
73
- get_tests()
74
-
75
- print("""
76
- if __name__ == '__main__':
77
- unittest.main()""")
tests/gen_test_fn.py DELETED
@@ -1,259 +0,0 @@
1
- import inspect
2
- import random
3
- import string
4
-
5
- from utils import *
6
-
7
- from klongpy import KlongInterpreter
8
- from klongpy.core import in_map, reserved_fn_symbol_map
9
-
10
-
11
- def wrap_lambda(arity, fn, fn_dict):
12
- if arity == 0:
13
- if len(fn_dict) == 0:
14
- return lambda: fn()
15
- elif 'm' in fn_dict and 'd' in fn_dict and 't' in fn_dict:
16
- return lambda m=fn_dict['m'],d=fn_dict['d'],t=fn_dict['t']: fn(m,d,t)
17
- elif 'm' in fn_dict and 'd' in fn_dict:
18
- return lambda m=fn_dict['m'],d=fn_dict['d']: fn(m,d)
19
- elif 'm' in fn_dict and 't' in fn_dict:
20
- return lambda m=fn_dict['m'],t=fn_dict['t']: fn(m,t)
21
- elif 'd' in fn_dict and 't' in fn_dict:
22
- return lambda d=fn_dict['d'],t=fn_dict['t']: fn(d,t)
23
- elif 'm' in fn_dict:
24
- return lambda m=fn_dict['m']: fn(m)
25
- elif 'd' in fn_dict:
26
- return lambda d=fn_dict['d']: fn(d)
27
- elif 't' in fn_dict:
28
- return lambda t=fn_dict['t']: fn(t)
29
- elif arity == 1:
30
- if len(fn_dict) == 0:
31
- return lambda x: fn(x)
32
- elif 'm' in fn_dict and 'd' in fn_dict and 't' in fn_dict:
33
- return lambda x,m=fn_dict['m'],d=fn_dict['d'],t=fn_dict['t']: fn(x,m=m,d=d,t=t)
34
- elif 'm' in fn_dict and 'd' in fn_dict:
35
- return lambda x,m=fn_dict['m'],d=fn_dict['d']: fn(x,m=m,d=d)
36
- elif 'm' in fn_dict and 't' in fn_dict:
37
- return lambda x,m=fn_dict['m'],t=fn_dict['t']: fn(x,m=m,t=t)
38
- elif 'd' in fn_dict and 't' in fn_dict:
39
- return lambda x,d=fn_dict['d'],t=fn_dict['t']: fn(x,d=d,t=t)
40
- elif 'm' in fn_dict:
41
- return lambda x,m=fn_dict['m']: fn(x,m=m)
42
- elif 'd' in fn_dict:
43
- return lambda x,d=fn_dict['d']: fn(x,d=d)
44
- elif 't' in fn_dict:
45
- return lambda x,t=fn_dict['t']: fn(x,t=t)
46
- elif arity == 2:
47
- if len(fn_dict) == 0:
48
- return lambda x,y: fn(x,y)
49
- elif 'm' in fn_dict and 'd' in fn_dict and 't' in fn_dict:
50
- return lambda x,y,m=fn_dict['m'],d=fn_dict['d'],t=fn_dict['t']: fn(x,y,m=m,d=d,t=t)
51
- elif 'm' in fn_dict and 'd' in fn_dict:
52
- return lambda x,y,m=fn_dict['m'],d=fn_dict['d']: fn(x,y,m=m,d=d)
53
- elif 'm' in fn_dict and 't' in fn_dict:
54
- return lambda x,y,m=fn_dict['m'],t=fn_dict['t']: fn(x,y,m=m,t=t)
55
- elif 'd' in fn_dict and 't' in fn_dict:
56
- return lambda x,y,d=fn_dict['d'],t=fn_dict['t']: fn(x,y,d=d,t=t)
57
- elif 'm' in fn_dict:
58
- return lambda x,y,m=fn_dict['m']: fn(x,y,m=m)
59
- elif 'd' in fn_dict:
60
- return lambda x,y,d=fn_dict['d']: fn(x,y,d=d)
61
- elif 't' in fn_dict:
62
- return lambda x,y,t=fn_dict['t']: fn(x,y,t=t)
63
- elif arity == 3:
64
- if len(fn_dict) == 0:
65
- return lambda x,y,z: fn(x,y,z)
66
- elif 'm' in fn_dict and 'd' in fn_dict and 't' in fn_dict:
67
- return lambda x,y,z,m=fn_dict['m'],d=fn_dict['d'],t=fn_dict['t']: fn(x,y,z,m=m,d=d,t=t)
68
- elif 'm' in fn_dict and 'd' in fn_dict:
69
- return lambda x,y,z,m=fn_dict['m'],d=fn_dict['d']: fn(x,y,z,m=m,d=d)
70
- elif 'm' in fn_dict and 't' in fn_dict:
71
- return lambda x,y,z,m=fn_dict['m'],t=fn_dict['t']: fn(x,y,z,m=m,t=t)
72
- elif 'd' in fn_dict and 't' in fn_dict:
73
- return lambda x,y,z,d=fn_dict['d'],t=fn_dict['t']: fn(x,y,z,d=d,t=t)
74
- elif 'm' in fn_dict:
75
- return lambda x,y,z,m=fn_dict['m']: fn(x,y,z,m=m)
76
- elif 'd' in fn_dict:
77
- return lambda x,y,z,d=fn_dict['d']: fn(x,y,z,d=d)
78
- elif 't' in fn_dict:
79
- return lambda x,y,z,t=fn_dict['t']: fn(x,y,z,t=t)
80
-
81
-
82
- class SymbolGenerator:
83
- def __init__(self):
84
- self.a = [n for n in list(string.ascii_lowercase) if not in_map(n, ['x','y','z','m','d','t'])]
85
- def __iter__(self):
86
- for n in self.a:
87
- yield n
88
- for n in self.a:
89
- for m in self.a:
90
- yield n+m
91
- for n in self.a:
92
- for m in self.a:
93
- for o in self.a:
94
- yield n+m+o
95
- for n in self.a:
96
- for m in self.a:
97
- for o in self.a:
98
- for p in self.a:
99
- yield n+m+o+p
100
-
101
-
102
- def create_symbols():
103
- return iter(SymbolGenerator())
104
-
105
- def gensym(symbols):
106
- return next(symbols)
107
-
108
- def fns(e,n,s):
109
- return e.replace(n,s)
110
-
111
- fn_map = {
112
- 0: [
113
- ("{0}", lambda: 0),
114
- ("{m(1)}", lambda m: m(1), 0),
115
- # ("{d}", lambda d: d, 2),
116
- # ("{d(1;)}", lambda d: lambda x: d(1,x), 1),
117
- ("{d(1;2)}", lambda d: d(1,2), 0),
118
- ("{d(1;m(2))}", lambda m,d: d(1,m(2)), 0),
119
- ("{d(m(2);1)}", lambda m,d: d(m(2),1), 0),
120
- # ("{t}", lambda t: t, 3),
121
- # ("{t(1;)}", lambda t: lambda x,y: t(1,x,y), 2),
122
- # ("{t(1;2;)}", lambda t: lambda x: t(1,2,x), 1),
123
- ("{t(1;2;3)}", lambda t: t(1,2,3), 0),
124
- ("{t(m(1);2;3)}", lambda m,t: t(m(1),2,3), 0),
125
- ("{t(1;m(2);3)}", lambda m,t: t(1,m(2),3), 0),
126
- ("{t(1;2;m(3))}", lambda m,t: t(1,2,m(3)), 0),
127
- ("{t(1;d(1;2);m(3))}", lambda m,d,t: t(1,d(1,2),m(3)), 0),
128
- ("{t(d(1;2);m(2);3)}", lambda m,d,t: t(d(1,2),m(2),3), 0),
129
- ("{t(d(1;2);2;m(3))}", lambda m,d,t: t(d(1,2),2,m(3)), 0),
130
- ("{t(1;m(2);d(1;2))}", lambda m,d,t: t(1,m(2),d(1,2)), 0),
131
- ("{t(m(1);d(1;2);3)}", lambda m,d,t: t(m(1),d(1,2),3), 0),
132
- ("{t(m(1);2;d(1;2))}", lambda m,d,t: t(m(1),2,d(1,2)), 0),
133
- ],
134
- 1: [
135
- ("{x}", lambda x: x, 0),
136
- ("{m(x)}", lambda x,m: m(x), 0),
137
- ("{x;m(x)}", lambda x,m: m(x), 0),
138
- ("{x;m(2*x)}", lambda x,m: m(2*x), 0),
139
- # ("{.p(x)}", lambda x: str(x), 0),
140
- # ("{d(x;)}", lambda d,x: lambda x1: d(x, x1), 1),
141
- ("{d(x;x)}", lambda x,d: d(x,x), 0),
142
- ("{d(1;x)}", lambda x,d: d(1, x), 0),
143
- ("{d(x;1)}", lambda x,d: d(x, 1), 0),
144
- ("{d(x;m(x))}", lambda x,m,d: d(x, m(x)), 0),
145
- ("{d(m(x);x)}", lambda x,m,d: d(m(x), x), 0),
146
- # ("{t(x;;)}", lambda t,x: lambda x1,y: t(x,x1,y), 2),
147
- # ("{t(x;x;)}", lambda t,x: lambda x1: t(x,x,x1), 1),
148
- ("{t(x;x;x)}", lambda x,t: t(x,x,x), 0),
149
- ("{t(1;x;x)}", lambda x,t: t(1,x,x), 0),
150
- ("{t(x;1;x)}", lambda x,t: t(x,1,x), 0),
151
- ("{t(x;x;1)}", lambda x,t: t(x,x,1), 0),
152
- ("{t(x;1;x)}", lambda x,t: t(x,1,x), 0),
153
- ("{t(1;2;x)}", lambda x,t: t(1,2,x), 0),
154
- ("{t(1;x;2)}", lambda x,t: t(1,x,2), 0),
155
- ("{t(2;x;1)}", lambda x,t: t(2,x,1), 0),
156
- ("{t(x;1;2)}", lambda x,t: t(x,1,2), 0),
157
- ("{t(x;2;1)}", lambda x,t: t(x,2,1), 0),
158
- ],
159
- 2: [
160
- ("{x+y}", lambda x,y: x+y),
161
- ("{x+m(y)}", lambda x,y,m: x+m(y), 0),
162
- ("{m(x)+m(y)}", lambda x,y,m: m(x)+m(y), 0),
163
- # ("{t(x;y;)}", lambda t,x,y: lambda x1: t(x,y,x1), 1),
164
- ("{t(x;y;y)}", lambda x,y,t: t(x,y,y), 0),
165
- ("{t(x;y;m(y))}", lambda x,y,m,t: t(x,y,m(y)), 0),
166
- ("{t(x;d(x;y);m(y))}", lambda x,y,m,d,t: t(x,d(x,y),m(y)), 0),
167
- ],
168
- 3: [
169
- ("{x+y+z}", lambda x,y,z: x+y+z, 0),
170
- ("{x+y+m(z)}", lambda x,y,z,m: x+y+m(z), 0),
171
- ("{m(x)+m(y)+m(z)}", lambda x,y,z,m: m(x)+m(y)+m(z), 0),
172
- ("{x+d(y;z)}", lambda x,y,z,d: x+d(y,z), 0),
173
- ("{m(x)+d(y;z)}", lambda x,y,z,m,d: m(x) + d(y,z), 0),
174
- ("{d(x;y)+m(z)}", lambda x,y,z,m,d: d(x,y) + m(z), 0),
175
- ("{d(x;y)+d(x;z)}", lambda x,y,z,d: d(x,y) + d(x,z), 0),
176
- ("{d(x;m(y))+d(m(x);z)}", lambda x,y,z,m,d: d(x,m(y)) + d(m(x),z), 0),
177
- # ("{d(m(x+y+z);)}", lambda x,y,z,m,d: lambda x1: d(m(x)+y+z,x1), 1)
178
- ]
179
- }
180
-
181
- def gen_fn(arity,symbols,fn_name=None,level=0,max_level=100):
182
- if level > max_level:
183
- raise RecursionError()
184
- arr = []
185
- choices = fn_map[arity]
186
- q = choices[random.randint(0,len(choices)-1)]
187
- fnd = q[0]
188
- fn_name = fn_name or gensym(symbols)
189
- if fn_name is None:
190
- return arr
191
- args = inspect.getfullargspec(q[1]).args
192
- fn_dict = {}
193
- if len(args) == 0:
194
- pass
195
- else:
196
- if 'm' in args:
197
- s = gensym(symbols)
198
- fnd = fns(fnd,'m',s)
199
- _,aa,ff = gen_fn(1,symbols,fn_name=s,level=level+1)
200
- fn_dict['m'] = ff
201
- arr.extend(aa)
202
- if 'd' in args:
203
- s = gensym(symbols)
204
- fnd = fns(fnd,'d',s)
205
- _,aa,ff = gen_fn(2,symbols,fn_name=s,level=level+1)
206
- fn_dict['d'] = ff
207
- arr.extend(aa)
208
- if 't' in args:
209
- s = gensym(symbols)
210
- fnd = fns(fnd,'t',s)
211
- _,aa,ff = gen_fn(3,symbols,fn_name=s,level=level+1)
212
- fn_dict['t'] = ff
213
- arr.extend(aa)
214
- fn = f"{fn_name}::{fnd}"
215
- arr.append(fn)
216
- return fn_name,arr,wrap_lambda(arity,q[1],fn_dict)
217
-
218
-
219
- def gen_tests():
220
- random.seed(0)
221
- seen = set()
222
- for arity in range(4):
223
- for _ in range(10000):
224
- try:
225
- fn_name, arr, fn = gen_fn(arity,create_symbols(), max_level=100)
226
- except RecursionError as e:
227
- continue
228
- klong = KlongInterpreter()
229
- stmt = "; ".join(arr)
230
- if stmt in seen or len(arr) > 10: # filter out redundant and too complex (slow) calcs
231
- continue
232
- seen.add(stmt)
233
- klong(stmt)
234
- if arity == 0:
235
- fr = fn()
236
- kr = f"{fn_name}()"
237
- else:
238
- args = [1,2,3][:arity]
239
- fr = fn(*args)
240
- kr = f"{fn_name}({';'.join([str(x) for x in args])})"
241
- print(stmt)
242
- print(f't(\"{stmt}; {kr}\"; {kr}; {fr})')
243
-
244
-
245
- if __name__ == '__main__':
246
- print("""
247
- :"DO NOT MODIFY: GENERATED BY gen_test_fn.py"
248
-
249
- err::0
250
- wl::{.w(x);.p("")}
251
- fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]}
252
- t::{:[~y~z;fail(x;y;z);[]]}
253
-
254
- """)
255
- gen_tests()
256
-
257
- print("""
258
- :[err;[];.p("ok!")]
259
- """)
tests/perf_async.py DELETED
@@ -1,25 +0,0 @@
1
- import timeit
2
- import asyncio
3
-
4
- # Non-async function with recursive calls
5
- def normal_function(n):
6
- if n == 0:
7
- return 1
8
- return normal_function(n-1) + 1
9
-
10
- # Async function with recursive calls
11
- async def async_function(n):
12
- if n == 0:
13
- return 1
14
- return await async_function(n-1) + 1
15
-
16
- # Wrapper function to run async function
17
- def run_async_function():
18
- return asyncio.run(async_function(10))
19
-
20
- # Measure the time taken by both functions
21
- non_async_time = timeit.timeit("normal_function(10)", globals=globals(), number=100000)
22
- async_time = timeit.timeit("run_async_function()", globals=globals(), number=100000)
23
-
24
- print(f"Non-async time: {non_async_time:.6f} seconds")
25
- print(f"Async time: {async_time:.6f} seconds")
tests/perf_avg.py DELETED
@@ -1,18 +0,0 @@
1
- import time
2
- from klongpy.backend import np
3
- from klongpy import KlongInterpreter
4
-
5
- klong = KlongInterpreter()
6
-
7
- # define average function in Klong. Note, the '+/' (sum over) uses np.add.reduce under the hood
8
- klong('avg::{(+/x)%#x}')
9
-
10
- # create a billion random ints
11
- data = np.random.rand(10**9)
12
-
13
- # run Klong average function
14
- start = time.perf_counter_ns()
15
- r = klong['avg'](data)
16
- stop = time.perf_counter_ns()
17
-
18
- print(f"avg={np.round(r,6)} in {round((stop - start) / (10**9),6)} seconds")
tests/perf_duckdb.py DELETED
@@ -1,32 +0,0 @@
1
- import duckdb
2
- import numpy as np
3
- import pandas as pd
4
- import time
5
-
6
- N = 1000000
7
-
8
- # Create a NumPy array
9
- data = np.arange(N, dtype=int)
10
- data2 = np.arange(N, dtype=int)
11
-
12
- df = pd.DataFrame({'c': data, 'd': data2})
13
-
14
- con = duckdb.connect(':memory:')
15
-
16
- # Register the DataFrame as a DuckDB table
17
- #start_t = time.time_ns()
18
- #con.register('T', df)
19
- #print("register: ", time.time_ns() - start_t)
20
-
21
- def call_db(sql, T):
22
- start_t = time.time_ns()
23
- result = con.execute(f'SELECT * FROM T where c > {N-10} and d > {N-5}').fetchdf()
24
- return time.time_ns() - start_t
25
-
26
- avgs = []
27
- sql = f'SELECT * FROM df where c > {N-10} and d > {N-5}'
28
- for i in range(1000):
29
- avgs.append(call_db(sql,df))
30
- avg = sum(avgs)/len(avgs)
31
- print(N, avg, avg / len(data))
32
-
tests/perf_gen.py DELETED
@@ -1,38 +0,0 @@
1
- import glob
2
- import math
3
- import os
4
- import unittest
5
-
6
- from utils import *
7
-
8
- import timeit
9
-
10
- def parse_suite_file(fname, number=10):
11
- klong = KlongInterpreter()
12
- with open(fname, "r") as f:
13
- d = f.read()
14
- b = len(d) * number
15
- r = timeit.timeit(lambda: klong(d), number=number)
16
- return b, r, int(b / r), r / number
17
-
18
-
19
- def test_kgtests():
20
- """
21
- Recursively run all tests under the kgtests folder that begin with "test" and end with ".kg".
22
- """
23
- root_dir = os.path.join(os.getcwd(), "tests", "kgtests")
24
-
25
- for dirpath, _, filenames in os.walk(root_dir):
26
- for fname in filenames:
27
- if (fname.startswith("gen")) and fname.endswith(".kg"):
28
- ran_tests = True
29
- klong = KlongInterpreter()
30
- fullpath = os.path.join(dirpath, fname)
31
- klong['fullpath'] = fullpath
32
- klong('.l("tests/kgtests/runner.kg")')
33
- if fname.startswith("gen"):
34
- r = parse_suite_file(fullpath)
35
- print(f"total: {r[1]} iter: {r[-1]}")
36
-
37
- if __name__ == "__main__":
38
- test_kgtests()
@@ -1,34 +0,0 @@
1
- import timeit
2
- import uuid
3
- import queue
4
- import threading
5
-
6
- def gen_uuid_msg_id():
7
- return uuid.uuid4().bytes
8
-
9
- def alloc_queue():
10
- return queue.Queue()
11
-
12
- def alloc_event():
13
- return threading.Event()
14
-
15
- def nop_fn():
16
- return 1
17
-
18
- def implicit_lambda():
19
- foo = 1
20
- def return_foo():
21
- return foo
22
- return return_foo()
23
-
24
- nop_fn = timeit.timeit("nop_fn()", globals=globals(), number=100000)
25
- gen_uuid_time = timeit.timeit("gen_uuid_msg_id()", globals=globals(), number=100000)
26
- alloc_queue_time = timeit.timeit("alloc_queue()", globals=globals(), number=100000)
27
- alloc_event_time = timeit.timeit("alloc_event()", globals=globals(), number=100000)
28
- implicit_lambda_time = timeit.timeit("implicit_lambda()", globals=globals(), number=100000)
29
-
30
- print(f"nop_fn: {nop_fn:.6f} seconds per: {nop_fn/100000}")
31
- print(f"gen_uuid_time: {gen_uuid_time:.6f} seconds per: {gen_uuid_time/100000}")
32
- print(f"alloc_queue_time: {alloc_queue_time:.6f} seconds per: {alloc_queue_time/100000}")
33
- print(f"alloc_event_time: {alloc_event_time:.6f} seconds per: {alloc_event_time/100000}")
34
- print(f"implicit_lambda_time: {implicit_lambda_time:.6f} seconds per: {implicit_lambda_time/100000}")
tests/perf_join.py DELETED
@@ -1,53 +0,0 @@
1
- import sys
2
- from os import path
3
- sys.path.append(path.abspath(path.join(path.dirname(__file__), '..')))
4
-
5
- from utils import *
6
- from klongpy.core import read_string
7
- import timeit
8
-
9
-
10
- def perf_join(k,number):
11
- a = "a" * k
12
- b = [x for x in a]
13
- r = timeit.timeit(lambda b=b: "".join(b), number=number)
14
- kr = r/number
15
- print(k,kr)
16
- return kr
17
-
18
-
19
- def perf_read_string(s, number=1000):
20
- i = s.index('"')+1
21
- r = timeit.timeit(lambda t=s,i=i: read_string(t,i), number=number)
22
- kr = r/number
23
- print(s, kr)
24
- return kr
25
-
26
-
27
- """
28
- some basic perf test for python join operator.
29
- """
30
-
31
- if __name__ == "__main__":
32
- perf_join(100,10000)
33
- perf_join(1000,10000)
34
- perf_join(10000,10000)
35
-
36
- t = '"hello"'
37
- perf_read_string(t)
38
- t = 'this is "hello" test'
39
- perf_read_string(t)
40
- t = 'this is "hello""""world" test'
41
- perf_read_string(t)
42
- t = 'this is "hello""""""world" test'
43
- perf_read_string(t)
44
- t = '""'
45
- perf_read_string(t)
46
- t = '""""'
47
- perf_read_string(t)
48
- t = '""""""'
49
- perf_read_string(t)
50
- t = '":["""";1;2]"'
51
- perf_read_string(t)
52
- t = 'A::""hello, world!""'
53
- perf_read_string(t)
tests/perf_load.py DELETED
@@ -1,17 +0,0 @@
1
- import os
2
- import timeit
3
-
4
- import numpy as np
5
- from utils import load_lib_file
6
-
7
- from klongpy import KlongInterpreter
8
-
9
-
10
- def perf_load_lib(number=100):
11
- r = timeit.timeit(lambda: load_lib_file('nstat.kg'), number=number)
12
- return r/number
13
-
14
-
15
- if __name__ == "__main__":
16
- number = 1000
17
- perf_load_lib(1000)
tests/perf_prog.py DELETED
@@ -1,18 +0,0 @@
1
- import timeit
2
-
3
- from klongpy import KlongInterpreter
4
-
5
-
6
- def parse_suite_file(fname, number=10):
7
- klong = KlongInterpreter()
8
- with open(f"tests/{fname}", "r") as f:
9
- d = f.read()
10
- b = len(d) * number
11
- r = timeit.timeit(lambda: klong.prog(d), number=number)
12
- return b, r, int(b / r), r / number
13
-
14
-
15
- if __name__ == "__main__":
16
- number = 20
17
- b,r,bps,avg = parse_suite_file("kgtests/language/test_join_over.kg", number=number)
18
- print(f"bytes processed: {b} time: {round(r,5)} bytes-per-second: {bps} time-per-pass: {round(avg,5)}")
tests/perf_serdes.py DELETED
@@ -1,52 +0,0 @@
1
- import numpy as np
2
- import pickle
3
- import dill
4
- import timeit
5
- import zlib
6
-
7
- # Create a large numpy array
8
- #large_array = np.random.rand(10000, 10000)
9
- large_array = np.random.rand(100000)
10
-
11
- size_in_bytes = large_array.nbytes
12
- print(f"Size of the numpy array: {size_in_bytes} bytes")
13
- print()
14
-
15
- # Define number of iterations
16
- N = 10
17
-
18
- # Pickle serialization
19
- pickle_serialize_time = timeit.timeit(lambda: pickle.dumps(large_array), number=N)
20
- print(f"Average pickle serialization time: {pickle_serialize_time / N} seconds")
21
-
22
- # Pickle deserialization
23
- pickle_data = pickle.dumps(large_array)
24
- print("len(pickle_data): ",len(pickle_data))
25
- pickle_deserialize_time = timeit.timeit(lambda: pickle.loads(pickle_data), number=N)
26
- print(f"Average pickle deserialization time: {pickle_deserialize_time / N} seconds")
27
- print()
28
-
29
- # Dill serialization
30
- dill_serialize_time = timeit.timeit(lambda: dill.dumps(large_array), number=N)
31
- print(f"Average dill serialization time: {dill_serialize_time / N} seconds")
32
-
33
- # Dill deserialization
34
- dill_data = dill.dumps(large_array)
35
- print("len(dill_data): ",len(dill_data))
36
- dill_deserialize_time = timeit.timeit(lambda: dill.loads(dill_data), number=N)
37
- print(f"Average dill deserialization time: {dill_deserialize_time / N} seconds")
38
- print()
39
-
40
- # Dill serialization with deflate
41
- dill_serialize_time = timeit.timeit(lambda: zlib.compress(dill.dumps(large_array), level=0), number=N)
42
- print(f"Average dill serialization time with deflate: {dill_serialize_time / N} seconds")
43
- print()
44
-
45
- # Dill deserialization with deflate
46
- dill_data = zlib.compress(dill.dumps(large_array),level=0)
47
- print("len(compressed_dill_data): ",len(dill_data))
48
- dill_deserialize_time = timeit.timeit(lambda: dill.loads(zlib.decompress(dill_data)), number=N)
49
- print(f"Average dill deserialization time with deflate: {dill_deserialize_time / N} seconds")
50
- print()
51
-
52
-