Skip to content

Instantly share code, notes, and snippets.

@postmodern
Created August 28, 2021 12:13
Show Gist options
  • Save postmodern/297bff869107e387b47a795e7c0c2733 to your computer and use it in GitHub Desktop.
Save postmodern/297bff869107e387b47a795e7c0c2733 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'benchmark'
require 'socket'
Benchmark.bm(20) do |b|
n = 10_000_000
def positional_args(one,two,three,four,five)
end
b.report('position arguments') do
n.times do
positional_args(1,2,3,4,5)
end
end
def keyword_args(one: , two: , three: , four: , five: )
end
b.report('keyword args') do
n.times do
keyword_args(one: 1, two: 2, three: 3, four: 4, five: 5)
end
end
end
user system total real
position arguments 0.787944 0.000821 0.788765 ( 0.797133)
keyword args 1.091629 0.000020 1.091649 ( 1.096063)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment