~bigbes/tarantool

tarantool-protobuf

ref: dbbfaf3555b5cd0fbc76ec1c9e69c5c87072dc97 tarantool-protobuf/bench/map_bench.lua -rw-r--r-- 1.9 KiB
dbbfaf35 — Eugene Blikh codegen: inline 1-byte varint fast path for packed scalar elements (aah) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env tarantool
-- Map-field encode microbench for ch2 verification.
-- Person has `ages_by_nickname` (map<string,int32>) which we populate
-- across multiple sizes and time encode-only throughput.
--
-- Run before and after the ch2 codegen change; compare medians.
-- The build_person_payload from bench/bench.lua doesn't exercise maps,
-- so the headline perf log can't show this. This script fills the gap.

package.path = './runtime/?.lua;./runtime/?/init.lua;'
    .. './examples/expected/?.lua;./examples/expected/?/init.lua;'
    .. package.path

local clock = require('clock')
local hello_full    = require('full.hello.hello_pb')
local hello_runtime = require('runtime.hello.hello_pb')

local function build(n_entries)
    local m = {}
    for i = 1, n_entries do
        m['nick_' .. tostring(i)] = i
    end
    return {name = 'bigbes', age = 42, ages_by_nickname = m}
end

local SIZES = {1, 3, 10, 50, 200}

local function bench_one(label, fn, p, encoded_bytes)
    for _ = 1, 1000 do fn(p) end
    local probe = 5000
    local t0 = clock.proc()
    for _ = 1, probe do fn(p) end
    local dt = clock.proc() - t0
    local rate = probe / dt
    local iters = math.max(probe, math.min(2000000, math.floor(rate * 0.5)))
    t0 = clock.proc()
    for _ = 1, iters do fn(p) end
    dt = clock.proc() - t0
    local msgs = iters / dt
    local mb = msgs * encoded_bytes / 1024 / 1024
    print(string.format('  %-40s  %10.0f msgs/s  %8.1f MB/s', label, msgs, mb))
    return msgs
end

print('=== Map encode bench (Person.ages_by_nickname, map<string,int32>) ===')
for _, n_entries in ipairs(SIZES) do
    local p = build(n_entries)
    local bytes = #hello_full.Person_encode(p)
    print(string.format('\n[map size %d, encoded %d bytes]', n_entries, bytes))
    bench_one('full Person_encode',    hello_full.Person_encode,    p, bytes)
    bench_one('runtime Person_encode', hello_runtime.Person_encode, p, bytes)
end