mirror of
https://github.com/aziascreations/PB-MessagePack.git
synced 2026-11-24 18:28:44 +01:00
Added examples, Added performance tests, Updated readme
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# Writes and reads the workload shared with the PureBasic tests, see `_Workload.pbi`.
|
||||
# The maps are packed from and unpacked to dicts, how they're usually handled in Python.
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import msgpack
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
from _PerfTesting import run
|
||||
|
||||
MAPS = 100_000
|
||||
MAP = {f"Key{i:02}": i for i in range(16)}
|
||||
|
||||
|
||||
def write():
|
||||
packer = msgpack.Packer(autoreset=False)
|
||||
pack = packer.pack
|
||||
for _ in range(MAPS):
|
||||
pack(MAP)
|
||||
return packer.bytes()
|
||||
|
||||
|
||||
def read():
|
||||
unpacker = msgpack.Unpacker(raw=False)
|
||||
unpacker.feed(ENCODED)
|
||||
unpack = unpacker.unpack
|
||||
total = 0
|
||||
for _ in range(MAPS):
|
||||
for key, value in unpack().items():
|
||||
total += len(key) + value
|
||||
return total
|
||||
|
||||
|
||||
ENCODED = write()
|
||||
|
||||
run("write", MAPS, lambda: len(write()))
|
||||
run("read", MAPS, read)
|
||||
Reference in New Issue
Block a user