The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
ERB made faster (by about 40%?)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ryan Davis

Posts: 651
Nickname: zenspider
Registered: Oct, 2004

Ryan Davis is a ruby nerd.
ERB made faster (by about 40%?) Posted: Sep 7, 2006 4:09 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Ryan Davis.
Original Post: ERB made faster (by about 40%?)
Feed Title: Polishing Ruby
Feed URL: http://blog.zenspider.com/index.rdf
Feed Description: Musings on Ruby and the Ruby Community...
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Ryan Davis
Latest Posts From Polishing Ruby

Advertisement
require 'benchmark'
require 'erb'

max = (ARGV.shift || 1_000_000).to_i

def validate(src)
  expect = "blah blah 2 " * 50
  result = eval(src)
  unless expect == result then
    raise "expected\n<#{expect}>\nbut got\n<#{result}>\n"
  end
end

def run
  iters = [10, 100, 1_000, 10_000, 100_000]
  Hash[*iters.map { |max|
         real = Benchmark::measure do
           src = []
           50.times { src << "blah blah <%= 1 + 1 %> " }
           src = src.join

           src = ERB.new(src).src

           validate src

           for i in 0..max do
             eval src
           end
         end.real
         [max, real]
       }.flatten]
end

before = run
require 'make_erb_fast' # patches 3 methods
after = run

before.keys.sort.each do |iter|
  puts "%6d\t%6.4f\t%6.4f" % [iter, before[iter], after[iter]]
end

begets:

erb.png

Read: ERB made faster (by about 40%?)

Topic: Tim Bray on Ruby IDEs Previous Topic   Next Topic Topic: Using the ActiveRecord-JDBC Adapter

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use