Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added comparison benchmarks for x |= y, x ||= y.

  • Loading branch information...
commit 4e8eced68951983f33035d98d6f2dd105e04ffda 1 parent abdbbc9
@brixen brixen authored
Showing with 46 additions and 0 deletions.
  1. +46 −0 benchmark/patterns/bench_flag_propagate.rb
View
46 benchmark/patterns/bench_flag_propagate.rb
@@ -0,0 +1,46 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+Benchmark.ips do |x|
+ x.compare!
+
+ x.report "x ||= y (false)" do |times|
+ x = false
+ y = false
+ i = 0
+ while i < times
+ x ||= y
+ i += 1
+ end
+ end
+
+ x.report "x |= y (false)" do |times|
+ x = false
+ y = false
+ i = 0
+ while i < times
+ x |= y
+ i += 1
+ end
+ end
+
+ x.report "x ||= y (true)" do |times|
+ x = true
+ y = true
+ i = 0
+ while i < times
+ x ||= y
+ i += 1
+ end
+ end
+
+ x.report "x |= y (true)" do |times|
+ x = true
+ y = true
+ i = 0
+ while i < times
+ x |= y
+ i += 1
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.