summaryrefslogtreecommitdiff
path: root/bench/bench_strlen.rb
diff options
context:
space:
mode:
Diffstat (limited to 'bench/bench_strlen.rb')
-rw-r--r--bench/bench_strlen.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/bench/bench_strlen.rb b/bench/bench_strlen.rb
index 98d9753..424a8bf 100644
--- a/bench/bench_strlen.rb
+++ b/bench/bench_strlen.rb
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), "bench_helper"))
-str = "test"
module LibC
extend FFI::Library
ffi_lib 'c'
@@ -10,10 +9,18 @@ if LibC.strlen("test") != 4
raise ArgumentError, "FFI.strlen returned incorrect value"
end
+
puts "Benchmark FFI api strlen(3) performance, #{ITER}x"
+str = 'test' * 10
10.times {
puts Benchmark.measure {
ITER.times { LibC.strlen(str) }
}
}
+puts "Benchmark FFI api strlen(3), with new string performance, #{ITER}x"
+10.times {
+ puts Benchmark.measure {
+ ITER.times { LibC.strlen('test' * 10) }
+ }
+}