Skip to content

Instantly share code, notes, and snippets.

@rossta
Created January 2, 2020 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossta/cc8f547dfe4967c8c2c67e36b1f24414 to your computer and use it in GitHub Desktop.
Save rossta/cc8f547dfe4967c8c2c67e36b1f24414 to your computer and use it in GitHub Desktop.
Comparing open from disk to open-uri
require "benchmark"
require "open-uri"
require "pathname"
n = 1_000
Benchmark.bm do |benchmark|
benchmark.report("open(url).read") do
n.times do
open("http://localhost:3035/packs/manifest.json").read
end
end
benchmark.report("Pathname.new(path).read") do
n.times do
Pathname.new("./public/packs/manifest.json").read
end
end
end
@rossta
Copy link
Author

rossta commented Jan 2, 2020

On my machine (MacBook Pro, 15", mid 2014, 2.8 GHz Quad-Core Intel Core i7):

       user     system      total        real
open(url).read  0.497777   0.269930   0.767707 (  6.950559)
Pathname.new(path).read  0.009915   0.020251   0.030166 (  0.031719)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment