MCPcopy Create free account
hub / github.com/apache/fory / benchmark_row_access

Function benchmark_row_access

python/pyfory/format/tests/test_encoder.py:240–262  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

238
239
240def benchmark_row_access():
241 encoder = pyfory.encoder(FooNested)
242 foo = FooNested(
243 f1=10,
244 f2=list(range(1000_000)),
245 f3={f"k{i}": i for i in range(1000_000)},
246 f4=[BarNested(f1=f"s{i}", f2=list(range(10))) for i in range(1000_000)],
247 )
248
249 binary_data = encoder.to_row(foo).to_bytes()
250
251 def benchmark_fory():
252 foo_row = pyfory.RowData(encoder.schema, binary_data)
253 print(foo_row.f2[100000], foo_row.f4[100000].f1, foo_row.f4[200000].f2[5])
254
255 print(timeit.timeit(benchmark_fory, number=10))
256 binary_data = pickle.dumps(foo)
257
258 def benchmark_pickle():
259 new_foo = pickle.loads(binary_data)
260 print(new_foo.f2[100000], new_foo.f4[100000].f1, new_foo.f4[200000].f2[5])
261
262 print(timeit.timeit(benchmark_pickle, number=10))

Callers

nothing calls this directly

Calls 6

FooNestedClass · 0.85
BarNestedClass · 0.85
listFunction · 0.50
to_bytesMethod · 0.45
to_rowMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected