Skip to content

Instantly share code, notes, and snippets.

@aumgn
Created November 27, 2012 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aumgn/4151701 to your computer and use it in GitHub Desktop.
Save aumgn/4151701 to your computer and use it in GitHub Desktop.
Grit/Graal Benchmark
require 'benchmark'
require 'grit'
require 'graal'
ChildProcess.posix_spawn = true
@benchmarks = {}
def benchmark(name, grit, graal)
@benchmarks[name] = lambda do
Benchmark.bmbm(12) do |bench|
bench.report("Grit #{name}") { N.times(&grit) }
bench.report("Graal #{name}") { N.times(&graal) }
end
puts
puts
end
end
grit = Grit::Repo.new('worldedit')
graal = Graal::Repository('worldedit')
benchmark(:heads,
proc { grit.heads },
proc { graal.heads })
benchmark(:tags,
proc { grit.tags },
proc { graal.tags })
benchmark(:commit,
proc { grit.commit('6d9e54a').id },
proc { graal.commit('6d9e54a').hash })
benchmark(:blobs,
proc { grit.head.commit.tree.blobs(&:id) },
proc { graal.blobs(&:hash) })
benchmark(:trees,
proc { grit.head.commit.tree.trees(&:id) },
proc { graal.trees(&:hash) })
benchmark(:blob_contents,
proc { grit.head.commit.tree./('README.md').data },
proc { graal['README.md'].contents })
N = (ARGV[1] || 1000).to_i
puts "Running each benchmarks #{N} times."
if ARGV[0].nil?
@benchmarks.values.each &:call
else
@benchmarks[ARGV[0].to_sym].call
end
Running each benchmark 1000 times.
Rehearsal ------------------------------------------------
Grit heads 0.000000 0.410000 0.410000 ( 5.257150)
Graal heads 1.150000 0.620000 4.130000 ( 36.643241)
--------------------------------------- total: 4.540000sec
user system total real
Grit heads 0.000000 0.160000 0.160000 ( 4.619689)
Graal heads 1.030000 0.590000 2.560000 ( 30.748539)
Rehearsal ------------------------------------------------
Grit tags 0.000000 0.440000 0.440000 ( 9.233773)
Graal tags 0.890000 0.720000 2.420000 ( 20.572091)
--------------------------------------- total: 2.860000sec
user system total real
Grit tags 0.000000 0.390000 0.390000 ( 9.150098)
Graal tags 0.880000 0.720000 2.390000 ( 20.457970)
Rehearsal ------------------------------------------------
Grit commit 0.380000 1.390000 2.560000 ( 33.811467)
Graal commit 1.110000 0.490000 2.390000 ( 17.268193)
--------------------------------------- total: 4.950000sec
user system total real
Grit commit 0.350000 1.490000 2.680000 ( 34.243838)
Graal commit 1.110000 0.470000 2.430000 ( 17.329665)
Rehearsal ------------------------------------------------
Grit blobs 0.740000 2.450000 4.000000 ( 44.344785)
Graal blobs 1.130000 0.500000 2.670000 ( 27.855033)
--------------------------------------- total: 6.670000sec
user system total real
Grit blobs 0.730000 2.400000 3.930000 ( 44.112603)
Graal blobs 1.140000 0.490000 2.750000 ( 28.833027)
Rehearsal ------------------------------------------------
Grit trees 0.720000 2.400000 3.950000 ( 43.529945)
Graal trees 1.130000 0.500000 2.650000 ( 27.974797)
--------------------------------------- total: 6.600000sec
user system total real
Grit trees 0.680000 2.410000 3.880000 ( 43.556516)
Graal trees 1.120000 0.530000 2.700000 ( 28.155585)
Rehearsal -------------------------------------------------------
Grit blob_contents 0.790000 3.010000 4.670000 ( 47.151627)
Graal blob_contents 2.180000 1.000000 4.830000 ( 42.530597)
---------------------------------------------- total: 9.500000sec
user system total real
Grit blob_contents 0.700000 3.080000 4.690000 ( 48.929303)
Graal blob_contents 2.200000 0.970000 4.760000 ( 42.643595)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment