Array.flatten performance issue
-------------------------------

                 Key: JRUBY-3821
                 URL: http://jira.codehaus.org/browse/JRUBY-3821
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.3.1
         Environment: Any
            Reporter: James Abley


$ cat bench-hash-creation.rb
require 'benchmark'

n = 1_000_000

Benchmark.bm do |x|
  x.report('arrays') {
    k = []
    v = []

    for i in 1..n do
      k << i
      v << i  
    end

    Hash[*k.zip(v).flatten]
  }

  x.report('direct') {
    h = {}
    
    for i in 1..n do
      h[i] = i
    end
  }
end

$ ruby bench-hash-creation.rb 
      user     system      total        real
arrays  2.740000   0.350000   3.090000 (  3.389127)
direct  1.040000   0.290000   1.330000 (  1.430653)

$ jruby --server bench-hash-creation.rb 
      user     system      total        real
arrays861.593000   0.000000 861.593000 (861.506000)
direct  4.180000   0.000000   4.180000 (  4.180000)


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to