Skip to content

Instantly share code, notes, and snippets.

@teamon
Created July 20, 2009 13:59
Show Gist options
  • Save teamon/150348 to your computer and use it in GitHub Desktop.
Save teamon/150348 to your computer and use it in GitHub Desktop.
require "benchmark"
require "fileutils"
def test
path = "/tmp/faketest"
FileUtils.mkdir_p("#{path}/public/stylesheets")
FileUtils.mkdir_p("#{path}/public/javascripts")
FileUtils.mkdir_p("#{path}/public/images")
FileUtils.mkdir_p("#{path}/views/templates")
FileUtils.mkdir_p("#{path}/views/layouts")
File.open("#{path}/views/layouts/application.html.haml", "w") {|f| f.write "= catch_content :for_layout\n" }
FileUtils.touch("#{path}/public/stylesheets/style.css")
FileUtils.touch("#{path}/public/stylesheets/.gitignore")
FileUtils.touch("#{path}/public/javascripts/.gitignore")
FileUtils.touch("#{path}/public/images/.gitignore")
FileUtils.touch("#{path}/views/templates/.gitignore")
FileUtils.rm_r(path)
end
n = 1000
Benchmark.bm(7) do |b|
b.report("FS:") { n.times { test } }
require "fakefs"
FakeFS.activate!
b.report("FakeFS:") { n.times { test } }
end
# % ruby fakefs_bench.rb
# user system total real
# FS: 1.460000 2.850000 4.310000 ( 5.456569)
# FakeFS: 1.600000 0.010000 1.610000 ( 1.680584)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment