Skip to content

Instantly share code, notes, and snippets.

@jmdeldin
Created December 15, 2014 22:55
Show Gist options
  • Save jmdeldin/172f779a8a4bfd9bfafd to your computer and use it in GitHub Desktop.
Save jmdeldin/172f779a8a4bfd9bfafd to your computer and use it in GitHub Desktop.
ruby laziness
require 'benchmark/ips'
START = 1
FINISH = 1_000_000
HALF = FINISH / 2
Benchmark.ips do |x|
x.report('lazy') do
(START..FINISH).lazy.include?(HALF)
end
x.report('nolazy') do
(START..FINISH).include?(HALF)
end
end
# -*- mode: ruby-compilation; default-directory: "~/src/sandbox/" -*-
# RubyComp started at Mon Dec 15 14:54:22
#
# ruby /home/jmdeldin/src/sandbox/lazy.rb
# Calculating -------------------------------------
# lazy 2.000 i/100ms
# nolazy 110.953k i/100ms
# -------------------------------------------------
# lazy 48.681 (± 2.1%) i/s - 244.000
# nolazy 4.018M (± 4.8%) i/s - 20.082M
#
# RubyComp finished at Mon Dec 15 14:54:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment