Created
March 24, 2014 11:40
-
-
Save chuckremes/9738668 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
require 'benchmark' | |
require 'benchmark/ips' | |
small_file = File.join(File.dirname(__FILE__), 'small.txt') | |
medium_file = File.join(File.dirname(__FILE__), 'medium.txt') | |
large_file = File.join(File.dirname(__FILE__), 'large.txt') | |
# Open these before the actual benchmarks so we don't also benchmark | |
# File.open(). | |
small_handle = File.open(small_file, 'r') | |
medium_handle = File.open(medium_file, 'r') | |
large_handle = File.open(large_file, 'r') | |
small_handle2 = File2.open_path(small_file) | |
medium_handle2 = File2.open_path(medium_file) | |
large_handle2 = File2.open_path(large_file) | |
small_handle3 = File3.open_path(small_file) | |
#small_handle2.each_byte { |byte| p byte } | |
#exit | |
#small_handle3.each_byte { |byte| p byte } | |
#exit | |
Benchmark.ips do |x| | |
x.report "File#each_byte with a small file" do | |
small_handle.each_byte {} | |
small_handle.rewind | |
end | |
x.report "File2#each_byte with a small file" do | |
small_handle2.each_byte {} | |
small_handle2.rewind | |
end | |
x.report "File3#each_byte with a small file" do | |
small_handle3.each_byte {} | |
small_handle3.rewind | |
end | |
# x.report "File#each_byte with a medium file" do | |
# medium_handle.each_byte {} | |
# medium_handle.rewind | |
# end | |
# | |
# x.report "File2#each_byte with a medium file" do | |
# medium_handle2.each_byte {} | |
# medium_handle2.rewind | |
# end | |
# | |
# x.report "File#each_byte with a large file" do | |
# large_handle.each_byte {} | |
# large_handle.rewind | |
# end | |
# | |
# x.report "File2#each_byte with a large file" do | |
# large_handle2.each_byte {} | |
# large_handle2.rewind | |
# end | |
end |
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
Charless-Mac-Pro:rubinius-benchmark cremes$ ./bin/benchmark core/file/bench_each_byte.rb | |
=== rbx === | |
File#each_byte with a small file | |
96.7 (±1.0%) i/s - 488 in 5.046986s (cycle=8) | |
File2#each_byte with a small file | |
767145.3 (±2.7%) i/s - 3855628 in 5.030246s (cycle=41909) | |
File3#each_byte with a small file | |
174259.2 (±3.6%) i/s - 880100 in 5.057088s (cycle=16925) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment