Sha256: 525286b84f08014f02913697259d978110ef0669713c9b3b792696faed410f36
Contents?: true
Size: 981 Bytes
Versions: 1
Compression:
Stored size: 981 Bytes
Contents
#!/usr/bin/env ruby require "bundler/setup" require "self_enumerable" class BenchmarkSelfEnumerable class DataSet def initialize(values) @values = values end def each return enum_for(__method__) unless block_given? @values.each do |_value| yield _value end end end class EnumerableDataSet < DataSet include Enumerable end class SelfEnumerableDataSet < DataSet include SelfEnumerable end def call require "benchmark/ips" values = [1,2,3,4,5,6,7,8,9,10] enumerable_data_set = EnumerableDataSet.new(values) self_enumerable_data_set = SelfEnumerableDataSet.new(values) Benchmark.ips do |x| callable = -> (_el) { _el } x.report("Enumerable#map") do enumerable_data_set.map(&callable) end x.report("SelfEnumerable#map") do self_enumerable_data_set.map(&callable) end x.compare! end end end BenchmarkSelfEnumerable.new.call
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
self_enumerable-0.1.0 | benchmark/benchmark_self_enumerable.rb |