-
-
Save rtomayko/e749138b066ed9d81fbe to your computer and use it in GitHub Desktop.
Benchmarks grit's ruby cat-file vs. native (sh) cat-file implementations
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
# Put this in your grit working directory and run with one of these blobs: | |
# | |
# large blob: 12044a76034e894c2412aea9c20508b5c8277784 | |
# medium blob: ab9d58aaebdb25385a21129b16e386fdaeee4b63 | |
# small blob: be391a3318952a73eaad63fd988ab1e201386965 | |
# | |
# Like this: | |
# | |
# ruby bench-string-concat.rb 12044a76034e894c2412aea9c20508b5c8277784 | |
$: << File.expand_path('lib') | |
require 'grit' | |
Grit::Git.git_max_size = 1_000_000_000 | |
git = Grit::Git.new('.git') | |
blob = ARGV.first | |
size = git.native(:cat_file, {:s => true}, blob).to_i | |
puts "blob: #{blob}" | |
puts "size: #{size}" | |
require 'benchmark' | |
include Benchmark | |
bm(30) do |measure| | |
measure.report("native cat_file") { | |
100.times { | |
data = git.native(:cat_file, {:p => true}, blob) | |
fail if data.size != size | |
} | |
} | |
measure.report("ruby cat_file") { | |
100.times { | |
data = git.cat_file({:p => true}, blob) | |
fail if data.size != size | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment