Last active
March 11, 2022 07:35
-
-
Save danini-the-panini/883baaa92c4dc4f8ed1a49134600576c to your computer and use it in GitHub Desktop.
Revisions
-
danini-the-panini revised this gist
Mar 11, 2022 . 2 changed files with 15 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,17 @@ Benchmark.ips do |x| x.report("reject") do arr = ARRAY.dup out = [] arr.reject! { _1 >= 0.5 } arr.each { out << _1 } end x.report("next") do arr = ARRAY.dup out = [] arr.each { next if _1 >= 0.5; out << _1 } end x.hold! 'temp_results' x.compare! end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,10 @@ Warming up -------------------------------------- reject 2.000 i/100ms next 2.000 i/100ms Calculating ------------------------------------- reject 20.503 (± 0.0%) i/s - 104.000 in 5.072750s next 25.475 (± 0.0%) i/s - 128.000 in 5.025467s Comparison: next: 25.5 i/s reject: 20.5 i/s - 1.24x (± 0.00) slower -
danini-the-panini revised this gist
Mar 11, 2022 . 2 changed files with 0 additions and 6 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +0,0 @@ -
danini-the-panini created this gist
Mar 11, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ require 'benchmark/ips' N = 1_000_000 ARRAY = N.times.map { rand } Benchmark.ips do |x| x.report("reject") do out = [] ARRAY.reject! { _1 >= 0.5 } ARRAY.each { out << _1 } end x.report("next") do out = [] ARRAY.each { next if _1 >= 0.5; out << _1 } end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ Warming up -------------------------------------- reject 2.000 i/100ms next 3.000 i/100ms Calculating ------------------------------------- reject 25.188 (± 0.0%) i/s - 126.000 in 5.002970s next 34.862 (± 0.0%) i/s - 177.000 in 5.077603s This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ Warming up -------------------------------------- reject 3.000 i/100ms next 5.000 i/100ms Calculating ------------------------------------- reject 36.357 (± 0.0%) i/s - 183.000 in 5.034273s next 58.647 (± 1.7%) i/s - 295.000 in 5.030860s