Created
March 24, 2010 07:46
-
-
Save frsyuki/342075 to your computer and use it in GitHub Desktop.
This file contains 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
# zero-copy enable-disable test | |
require 'msgpack' | |
require 'benchmark' | |
LOOP = 100000 | |
sizes = [10,100,1000,10000] | |
sizes.map! {|sz| [sz, MessagePack.pack("a"*sz)] } | |
Benchmark.benchmark(' ' * 30 + Benchmark::Tms::CAPTION, 30) do |b| | |
sizes.each {|sz, raw| | |
b.report("#{sz}") { | |
LOOP.times { MessagePack.unpack(raw) } | |
} | |
} | |
end | |
## | |
## zero-copy is enabled: | |
## | |
# user system total real | |
# 10 0.040000 0.000000 0.040000 ( 0.052139) | |
# 100 0.040000 0.010000 0.050000 ( 0.044704) | |
# 1000 0.040000 0.000000 0.040000 ( 0.047488) | |
# 10000 0.040000 0.000000 0.040000 ( 0.040828) | |
## | |
## zero-copy is disabled: | |
## | |
# user system total real | |
# 10 0.040000 0.000000 0.040000 ( 0.050760) | |
# 100 0.080000 0.020000 0.100000 ( 0.091826) | |
# 1000 0.100000 0.090000 0.190000 ( 0.197389) | |
# 10000 0.350000 0.930000 1.280000 ( 1.298983) | |
## disable zero-copy patch | |
# | |
# diff --git a/ruby/unpack.c b/ruby/unpack.c | |
# index 0f1af38..021ffa4 100644 | |
# --- a/ruby/unpack.c | |
# +++ b/ruby/unpack.c | |
# @@ -111,7 +111,15 @@ static inline int template_callback_map_item(unpack_user* u, VALUE* c, VALUE k, | |
# { rb_hash_aset(*c, k, v); return 0; } | |
# | |
# static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, VALUE* o) | |
# -{ *o = (l == 0) ? rb_str_new(0,0) : rb_str_substr(u->source, p - b, l); return 0; } | |
# +{ | |
# + if(l == 0) { | |
# + *o = rb_str_new(0,0); | |
# + } else { | |
# + *o = rb_str_new(p, l); | |
# + } | |
# + return 0; | |
# +} | |
# +//{ *o = (l == 0) ? rb_str_new(0,0) : rb_str_substr(u->source, p - b, l); return 0; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment