Skip to content

Instantly share code, notes, and snippets.

@teamon
Last active December 19, 2015 11:08
Show Gist options
  • Save teamon/5945105 to your computer and use it in GitHub Desktop.
Save teamon/5945105 to your computer and use it in GitHub Desktop.
shell vs code
require "tempfile"
require "bundler/cli"
require 'benchmark'
def run
$stdout = StringIO.new;
10.times do
Dir.mktmpdir do |dir|
yield(dir)
end
end
$stdout = STDOUT
end
Benchmark.bm do |x|
x.report("shell") do
run do |dir|
system "bundle gem rails-assets-moment > /dev/null", :chdir => dir
end
end
x.report("code ") do
run do |dir|
pid = fork do
Dir.chdir(dir) do
Bundler::CLI.start(["gem", "rails-assets-moment"])
end
end
Process.wait(pid)
end
end
end
# λ ruby bundler_bench.rb
# user system total real
# shell 0.020000 0.030000 7.390000 ( 7.455510)
# code 0.020000 0.050000 0.730000 ( 0.758425)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment