Skip to content

Dir[] slow, hot & cold #2092

Open
Open
@LillianZ

Description

@LillianZ

Even when hot (confirmed hot by Thermometer), Dir[] is almost 4x slower than MRI. Code snippet below was run in this directory, and MRI and Truffleruby output below.

Cold Hot
MRI 0.003747s 304.699 ips
Truffleruby 0.122712s 82.758 ips
require 'benchmark'
require 'benchmark/ips'
puts  Benchmark.measure {Dir["src/main/java/**/*"]}

Benchmark.ips do |x|
  x.config(:time => 5, :warmup => 10)
  x.report('Dir#[]') {Dir["src/main/java/**/*"]}
end

puts Benchmark.measure {Dir["src/main/java/**/*"]}
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
  0.000946   0.002803   0.003749 (  0.003747)
Warming up --------------------------------------
          Dir#[]    31.000  i/100ms
Calculating -------------------------------------
          Dir#[]    304.699  (± 5.6%) i/s -      1.519k in   5.000986s
  0.001018   0.002456   0.003474 (  0.003476)
truffleruby (Shopify) 20.3.0-dev-151cfcb0, like ruby 2.6.6, GraalVM CE JVM [x86_64-darwin]
  0.733384   0.017023   0.750407 (  0.122712)
Warming up --------------------------------------
          Dir#[]     6.000  i/100ms
Calculating -------------------------------------
          Dir#[]     82.758  (± 7.3%) i/s -    414.000  in   5.027133s
  0.047519   0.009553   0.057072 (  0.015891)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions