Skip to content

Instantly share code, notes, and snippets.

@technicalpickles
Created May 14, 2024 18:07
Show Gist options
  • Save technicalpickles/65c62a49d37cbdb5bf5ec1c8148b2763 to your computer and use it in GitHub Desktop.
Save technicalpickles/65c62a49d37cbdb5bf5ec1c8148b2763 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
Dir.chdir ARGV[0] if ARGV[0]
glob ='{app,components,config,frontend,lib,packs,spec,danger,script}/**/*.{rb,arb,erb,rake,js,jsx,ts,tsx}'
Benchmark.ips do |x|
x.report "Dir.glob" do
Dir.glob(glob)
end
x.report "fd" do |x|
`fd --full-path --glob '**/*.{rb,arb,erb,rake,js,jsx,ts,tsx}' | grep -e '^app/' -e '^components/' -e '^config' -e '^frontend/' -e '^lib/' -e '^packs/' -e '^spec/' -e '^danger/' -e '^script/'`
end
x.compare! order: :baseline
end
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
Dir.glob 1.000 i/100ms
fd 1.000 i/100ms
Calculating -------------------------------------
Dir.glob 0.060 (± 0.0%) i/s - 1.000 in 16.618777s
fd 0.223 (± 0.0%) i/s - 2.000 in 8.952842s
Comparison:
Dir.glob: 0.1 i/s
fd: 0.2 i/s - 3.71x faster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment