Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Path: optimize `join` for the case of joining one single part #8082
Follow up to #8078
When we just have two pieces to combine it becomes easier to compute the total bytesize needed for the string and we can use
This results in more code, but I think it's good if we optimize for this case because it's so common.
require "benchmark" base = "/Users/someone/foo/bar" parts = ["baz.cr"] Benchmark.ips do |x| x.report("join") do Path.new(base).join(parts) end end
That's twice as fast and with a third of the memory used.
Another benchmark (
require "benchmark" Benchmark.ips do |x| x.report("Dir.glob") do Dir.glob("*/*.cr") do end end end
Not a lot of speed improvement because the