| 238 | |
| 239 | |
| 240 | def 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)) |