mirror of
https://github.com/aziascreations/PB-MessagePack.git
synced 2026-11-03 17:01:24 +01:00
9facb66ee8
Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
# Writes, reads and skips the workload shared with the PureBasic tests, see `_Workload.pbi`.
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import msgpack
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
from _PerfTesting import run
|
|
|
|
RECORDS = 125_000
|
|
FIELDS = RECORDS * 8
|
|
|
|
|
|
def write():
|
|
packer = msgpack.Packer(autoreset=False)
|
|
pack = packer.pack
|
|
for _ in range(RECORDS):
|
|
pack(42)
|
|
pack(-5)
|
|
pack(200)
|
|
pack(-1000)
|
|
pack(70000)
|
|
pack(-1099511627776)
|
|
pack(3.14)
|
|
pack("Hello")
|
|
return packer.bytes()
|
|
|
|
|
|
def read():
|
|
unpacker = msgpack.Unpacker(raw=False)
|
|
unpacker.feed(ENCODED)
|
|
unpack = unpacker.unpack
|
|
total = 0
|
|
for _ in range(RECORDS):
|
|
total += unpack() + unpack() + unpack() + unpack() + unpack() + unpack()
|
|
total += int(unpack())
|
|
total += len(unpack())
|
|
return total
|
|
|
|
|
|
def skip():
|
|
unpacker = msgpack.Unpacker(raw=False)
|
|
unpacker.feed(ENCODED)
|
|
skip_field = unpacker.skip
|
|
for _ in range(FIELDS):
|
|
skip_field()
|
|
return FIELDS
|
|
|
|
|
|
ENCODED = write()
|
|
|
|
run("write", FIELDS, lambda: len(write()))
|
|
run("read", FIELDS, read)
|
|
run("skip", FIELDS, skip)
|