Skip to content

Commit e0f01b7

Browse files
authored
Add an encoding benchmark for ProtoBoeuf (#306)
Adds an encoding benchmark for ProtoBoeuf. I think it's easier for us to track and improve benchmarks if it's in YJIT-bench vs running the benchmarks in the upstream repo ad-hoc
1 parent 857b602 commit e0f01b7

File tree

5 files changed

+3924
-0
lines changed

5 files changed

+3924
-0
lines changed

benchmarks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ blurhash:
8585
desc: blurhash (blurred preview image) calculation
8686
protoboeuf:
8787
desc: protoboeuf (pure-Ruby protobuf) message decoding
88+
protoboeuf-encode:
89+
desc: protoboeuf (pure-Ruby protobuf) message encoding
8890

8991
#
9092
# MicroBenchmarks
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
syntax = "proto3";
2+
3+
package upstream;
4+
5+
//
6+
// This aims to be a larger, more representative benchmark
7+
// The messages intentionally use nesting and have many fields of
8+
// multiple different types.
9+
//
10+
11+
message Position
12+
{
13+
uint32 x = 1;
14+
uint32 y = 2;
15+
uint32 z = 3;
16+
}
17+
18+
message TrunkItem
19+
{
20+
enum ITEM_TYPE {
21+
LAPTOP = 0;
22+
DUFFEL_BAG = 1;
23+
GOLF_CLUBS = 2;
24+
BASEBALL_BAT = 3;
25+
SUITCASE = 4;
26+
BRICKS = 5;
27+
CROWBAR = 6;
28+
CASH = 7;
29+
POKEMON_CARDS = 8;
30+
}
31+
32+
enum COUNTRY {
33+
NOT_US_OF_A = 0; // Zero
34+
US_OF_A = 1; // Number 1
35+
CANADA = 2;
36+
}
37+
38+
string id = 1;
39+
string owner_id = 2;
40+
COUNTRY made_in = 3;
41+
uint64 width = 4;
42+
uint64 height = 5;
43+
uint64 depth = 6;
44+
uint64 weight = 7;
45+
bool is_usbc = 8;
46+
Position pos = 9;
47+
bool is_umbrella = 10;
48+
double monetary_value = 11;
49+
ITEM_TYPE item_type = 12;
50+
}
51+
52+
message Vehicle
53+
{
54+
enum VEHICLE_TYPE {
55+
CAR = 0;
56+
SPORTS_CAR = 1;
57+
SUV = 2;
58+
PICKUP_TRUCK = 3;
59+
MINIVAN = 4;
60+
MOTORCYCLE = 5;
61+
}
62+
63+
uint64 id = 1;
64+
string make = 2;
65+
string model = 3;
66+
uint64 owner_id = 4;
67+
uint32 year = 5;
68+
VEHICLE_TYPE type = 6;
69+
70+
bool is_electric = 7;
71+
uint32 num_doors = 8;
72+
uint32 num_wheels = 9;
73+
uint32 num_windows = 10;
74+
uint32 wheel_size = 11;
75+
76+
uint64 dry_weight = 12;
77+
uint64 trunk_volume = 13;
78+
double monetary_value = 14;
79+
80+
// List of items in the trunk
81+
repeated TrunkItem trunk_items = 15;
82+
83+
bool is_manual = 16;
84+
}
85+
86+
message ParkingSpace
87+
{
88+
Position pos = 1;
89+
bool has_electric_charger = 2;
90+
bool handicapped = 3;
91+
optional Vehicle vehicle = 4;
92+
}
93+
94+
message ParkingFloor
95+
{
96+
uint64 id = 1;
97+
98+
uint32 num_cameras = 4;
99+
uint32 num_fire_exits = 5;
100+
uint32 num_sprinklers = 6;
101+
double area_sqft = 7;
102+
103+
// inches because 'Murica
104+
// Also we don't want too many doubles because that
105+
// wouldn't be representative of most real-world use cases
106+
uint32 ceiling_height_inches = 8;
107+
108+
// List of vehicles
109+
repeated ParkingSpace parking_spaces = 9;
110+
}
111+
112+
message ParkingLot
113+
{
114+
string name = 1;
115+
string district = 2;
116+
string phone_number = 3;
117+
uint64 id = 4;
118+
uint32 num_floors = 5;
119+
uint32 num_entrances = 6;
120+
uint32 num_attendants = 7;
121+
122+
// List of floors
123+
repeated ParkingFloor floors = 8;
124+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require_relative '../../harness/loader'
2+
3+
# Protoboeuf decoder
4+
require_relative 'benchmark_pb'
5+
6+
Dir.chdir __dir__
7+
fake_msg_bins = Marshal.load(File.binread('encoded_msgs.bin'))
8+
lots = fake_msg_bins.map { |bin| ProtoBoeuf::ParkingLot.decode bin }
9+
10+
run_benchmark(20) do
11+
lots.each { |lot| ProtoBoeuf::ParkingLot.encode lot }
12+
end

0 commit comments

Comments
 (0)