Skip to content

Commit

Permalink
Add complex object benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
penguin-wwy committed Nov 5, 2024
1 parent 1910517 commit 4d0d715
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
50 changes: 47 additions & 3 deletions integration_tests/cpython_benchmark/fury_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
# under the License.

import argparse
import array
from dataclasses import dataclass
import datetime
import os
import random
import sys
from pyfury import Fury, Language
from typing import Any, Dict, List
import pyfury
import pyperf


Expand Down Expand Up @@ -105,8 +108,46 @@ def mutate_dict(orig_dict, random_source):
DICT_GROUP = [mutate_dict(DICT, random_source) for _ in range(3)]


@dataclass
class ComplexObject1:
f1: Any = None
f2: str = None
f3: List[str] = None
f4: Dict[pyfury.Int8Type, pyfury.Int32Type] = None
f5: pyfury.Int8Type = None
f6: pyfury.Int16Type = None
f7: pyfury.Int32Type = None
f8: pyfury.Int64Type = None
f9: pyfury.Float32Type = None
f10: pyfury.Float64Type = None
f11: pyfury.Int16ArrayType = None
f12: List[pyfury.Int16Type] = None


@dataclass
class ComplexObject2:
f1: Any
f2: Dict[pyfury.Int8Type, pyfury.Int32Type]


COMPLEX_OBJECT = ComplexObject1(
f1=ComplexObject2(f1=True, f2={-1: 2}),
f2="abc",
f3=["abc", "abc"],
f4={1: 2},
f5=2**7 - 1,
f6=2**15 - 1,
f7=2**31 - 1,
f8=2**63 - 1,
f9=1.0 / 2,
f10=1 / 3.0,
f11=array.array("h", [1, 2]),
f12=[-1, 4],
)


def fury_object(language, ref_tracking, obj):
fury = Fury(language=language, ref_tracking=ref_tracking)
fury = pyfury.Fury(language=language, ref_tracking=ref_tracking)
binary = fury.serialize(obj)
fury.deserialize(binary)

Expand All @@ -132,13 +173,16 @@ def micro_benchmark():
os.environ["ENABLE_FURY_CYTHON_SERIALIZATION"] = "0"
sys.argv += ["--inherit-environ", "ENABLE_FURY_CYTHON_SERIALIZATION"]
runner.parse_args()
language = Language.XLANG if args.xlang else Language.PYTHON
language = pyfury.Language.XLANG if args.xlang else pyfury.Language.PYTHON
runner.bench_func("fury_dict", fury_object, language, not args.no_ref, DICT)
runner.bench_func(
"fury_dict_group", fury_object, language, not args.no_ref, DICT_GROUP
)
runner.bench_func("fury_tuple", fury_object, language, not args.no_ref, TUPLE)
runner.bench_func("fury_list", fury_object, language, not args.no_ref, LIST)
runner.bench_func(
"fury_complex", fury_object, language, not args.no_ref, COMPLEX_OBJECT
)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion python/pyfury/_fury.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, data, hashcode=None):
self.data = data
self.length = len(data)
if hashcode is None:
hashcode = mmh3.hash_buffer(data, 47)[0] & 0xFFFFFFFFFFFFFF00
hashcode = (mmh3.hash_buffer(data, 47)[0] >> 8) << 8
self.hashcode = hashcode
self.dynamic_write_string_id = DEFAULT_DYNAMIC_WRITE_STRING_ID

Expand Down

0 comments on commit 4d0d715

Please sign in to comment.