Last active
August 29, 2015 14:21
-
-
Save huacnlee/e942ce9843b5c01bc7dd to your computer and use it in GitHub Desktop.
Benchmark sprockets-rails javascript_include_tag cache
This file contains hidden or 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
# sprockets-rails/test/test_railtie.rb | |
def test_benchmark_assets_tag | |
app.configure do | |
config.assets.paths << FIXTURES_PATH | |
config.assets.precompile += ["bar.js", "bar.css"] | |
end | |
app.initialize! | |
require 'benchmark/ips' | |
@monkey = ActionView::Base.new | |
# puts @monkey.javascript_include_tag("bar.js", "foo.js", title: "foo") | |
# puts @mock.stylesheet_link_tag("style.css", "theme.css", media: "all") | |
# exit | |
puts "\n\n" | |
ActionView::Resolver.caching = false | |
@monkey.javascript_include_tag("bar.js") | |
@monkey.stylesheet_link_tag("bar.css") | |
t1 = Time.now | |
@monkey.javascript_include_tag("bar.js") | |
@monkey.stylesheet_link_tag("bar.css") | |
puts "without cache = #{(Time.now - t1) * 1000}" | |
ActionView::Resolver.caching = true | |
# warmup | |
@monkey.javascript_include_tag("bar.js") | |
@monkey.stylesheet_link_tag("bar.css") | |
t2 = Time.now | |
@monkey.javascript_include_tag("bar.js") | |
@monkey.stylesheet_link_tag("bar.css") | |
puts "cache = #{(Time.now - t2) * 1000}" | |
# exit | |
Benchmark.ips do |x| | |
x.report("javascript_include_tag witout cache") { | |
ActionView::Resolver.caching = false | |
@monkey.javascript_include_tag("bar.js") | |
} | |
x.report("javascript_include_tag with cache") { | |
ActionView::Resolver.caching = true | |
@monkey.javascript_include_tag("bar.js") | |
} | |
x.compare! | |
end | |
Benchmark.ips do |x| | |
x.report("stylesheet_link_tag witout cache") { | |
ActionView::Resolver.caching = false | |
@monkey.stylesheet_link_tag("bar.css") | |
} | |
x.report("stylesheet_link_tag with cache") { | |
ActionView::Resolver.caching = true | |
@monkey.stylesheet_link_tag("bar.css") | |
} | |
x.compare! | |
end | |
end |
Author
huacnlee
commented
May 26, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment