Skip to content

Commit 17927ff

Browse files
committed
Edit benchmark
1 parent 3581be2 commit 17927ff

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

bench/various_appraches_bench.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
begin
2222
factory = MessagePack::Factory.new
2323
test_struct = Struct.new(:a, keyword_init: true)
24-
factory.register_type(0x01, test_struct, optimized_struct: true)
24+
factory.register_type(0x01, test_struct, optimized_struct: true, ref_tracking: true)
2525
obj = test_struct.new(a: 1)
2626
arr = [obj, obj, obj]
2727
dump = factory.dump(arr)
2828
loaded = factory.load(dump)
29+
30+
unless loaded[0].object_id == loaded[1].object_id
31+
puts "ERROR: msgpack-ruby does not support ref_tracking; the benchmark cannot run."
32+
exit(1)
33+
end
2934
rescue StandardError
3035
puts "ERROR: msgpack-ruby does not support optimized_struct; the benchmark cannot run."
3136
exit(2)
@@ -466,6 +471,37 @@ def self.description
466471
end
467472
end
468473

474+
module RefTrackingInC
475+
def self.build_factory
476+
factory = MessagePack::Factory.new
477+
Coders.register_time(factory)
478+
479+
type_id = 0x20
480+
ALL_STRUCTS.each do |struct|
481+
if SHARED_STRUCTS.include?(struct)
482+
factory.register_type(
483+
type_id,
484+
struct,
485+
optimized_struct: true,
486+
ref_tracking: true,
487+
)
488+
else
489+
factory.register_type(type_id, struct, optimized_struct: true)
490+
end
491+
type_id += 1
492+
end
493+
494+
factory
495+
end
496+
497+
def self.factory
498+
@factory ||= build_factory
499+
end
500+
501+
def self.description
502+
"Uses optimized_struct with C-level reference tracking for shared types"
503+
end
504+
end
469505
end
470506

471507
# =============================================================================

0 commit comments

Comments
 (0)