Skip to content

Instantly share code, notes, and snippets.

@JonathonMA
Created May 25, 2016 07:41
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 JonathonMA/eacea8bf6a25d11a826b489fd1e766f1 to your computer and use it in GitHub Desktop.
Save JonathonMA/eacea8bf6a25d11a826b489fd1e766f1 to your computer and use it in GitHub Desktop.
module ExponentialBackoffStrategyModule
module_function def call(exponent, value)
value ** exponent
end
end
class ExponentialBackoffStrategyClass
def initialize(exponent)
@exponent = exponent
end
def call(value)
value ** @exponent
end
end
curried = ExponentialBackoffStrategyModule.method(:call).curry.(4)
partialed = ->(x) { ExponentialBackoffStrategyModule.call(4, x) }
lambdad = ->(x) { x ** 4 }
klassed = ExponentialBackoffStrategyClass.new(4)
require 'fruity'
compare do
curry { curried.call(10) }
klass { klassed.call(10) }
partial { partialed.call(10) }
λ { lambdad.call(10) }
end
@JonathonMA
Copy link
Author

JonathonMA commented May 25, 2016

$ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
$ ruby curry.rb
Running each test 65536 times. Test will take about 2 seconds.
klass is faster than λ by 2x ± 0.1
λ is similar to partial
partial is faster than curry by 3x ± 0.1

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