Last active
November 28, 2016 16:55
-
-
Save TeWu/f1c8e9cc9159734712c033ec2f849a6e to your computer and use it in GitHub Desktop.
kRPC-rb: Benchmark message hashing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kRPC Benchmarks & Checks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'krpc' | |
require 'benchmark' | |
PB = KRPC::PB | |
n = 1_000_000 | |
def msg | |
PB::Type.new(code: :UINT32, service: "ala_ma_kota", name: "blahblah", types: [PB::Type.new(code: :STRING)]) | |
# PB::Type.new(code: :STRING) | |
end | |
puts "\n\n=== NO CACHING ===" | |
Benchmark.bmbm do |x| | |
x.report("inspect.hash") {n.times{ msg.inspect.hash }} | |
x.report("hash") {n.times{ msg.hash }} | |
x.report("to_proto.hash") {n.times{ msg.to_proto.hash }} | |
end | |
puts "\n\n=== WITH CACHING ===" | |
msg_cached = msg | |
Benchmark.bmbm do |x| | |
x.report("inspect.hash") {n.times{ msg_cached.inspect.hash }} | |
x.report("hash") {n.times{ msg_cached.hash }} | |
x.report("to_proto.hash") {n.times{ msg_cached.to_proto.hash }} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle exec ruby benchmark_message_hashing.rb | |
=== NO CACHING === | |
Rehearsal ------------------------------------------------- | |
inspect.hash 17.510000 0.000000 17.510000 ( 17.516609) | |
hash 8.390000 0.000000 8.390000 ( 8.383277) | |
to_proto.hash 8.690000 0.000000 8.690000 ( 8.700229) | |
--------------------------------------- total: 34.590000sec | |
user system total real | |
inspect.hash 17.480000 0.000000 17.480000 ( 17.474298) | |
hash 8.460000 0.000000 8.460000 ( 8.465600) | |
to_proto.hash 8.740000 0.000000 8.740000 ( 8.742383) | |
=== WITH CACHING === | |
Rehearsal ------------------------------------------------- | |
inspect.hash 9.350000 0.000000 9.350000 ( 9.341497) | |
hash 1.460000 0.000000 1.460000 ( 1.468629) | |
to_proto.hash 1.380000 0.000000 1.380000 ( 1.379006) | |
--------------------------------------- total: 12.190000sec | |
user system total real | |
inspect.hash 9.290000 0.000000 9.290000 ( 9.281887) | |
hash 1.520000 0.000000 1.520000 ( 1.518233) | |
to_proto.hash 1.360000 0.000000 1.360000 ( 1.365693) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'krpc' | |
# | |
################ | |
# Prints all doc strings | |
# WARNING: This script **invokes all RPCs** except one in IGNORED_RPCS array | |
################ | |
# | |
IGNORED_RPCS = %i[ quicksave quickload ] | |
$VISITED = Set.new | |
def test_doc(obj) | |
return unless obj.class.to_s.start_with? 'KRPC::' and not $VISITED.include? obj.inspect | |
$VISITED.add obj.inspect | |
obj.class.instance_methods(false).each do |m| | |
begin | |
next if IGNORED_RPCS.include? m | |
obj.send("#{m}_doc") | |
test_doc(obj.send(m)) | |
rescue Exception | |
end | |
end | |
end | |
KRPC.connect do |cl| | |
test_doc(cl.space_center) | |
test_doc(cl.drawing) | |
test_doc(cl.ui) | |
test_doc(cl.infernal_robotics) | |
test_doc(cl.kerbal_alarm_clock) | |
test_doc(cl.remote_tech) | |
test_doc(cl.drawing) | |
test_doc(cl.krpc) | |
test_doc(cl.core) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment