-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'benchmark/ips' | ||
|
||
Benchmark.ips do |x| | ||
# Typical mode, runs the block as many times as it can | ||
x.report("addition") { 1 + 2 } | ||
|
||
# To reduce overhead, the number of iterations is passed in | ||
# and the block must run the code the specific number of times. | ||
# Used for when the workload is very small and any overhead | ||
# introduces incorrectable errors. | ||
x.report(:addition2) do |times| | ||
i = 0 | ||
while i < times | ||
1 + 2 | ||
i += 1 | ||
end | ||
end | ||
|
||
# To reduce overhead even more, grafts the code given into | ||
# the loop that performs the iterations internally to reduce | ||
# overhead. Typically not needed, use the |times| form instead. | ||
x.report("addition3", "1 + 2") | ||
|
||
# Really long labels should be formatted correctly | ||
x.report("addition-test-long-label") { 1 + 2 } | ||
|
||
x.compare! | ||
end | ||
|
||
puts <<-EOD | ||
Typical results will show addition2 & addition3 to be the most performant, and | ||
they should perform reasonably similarly. You should see addition and | ||
addition-test-long-label to perform very similarly to each other (as they are | ||
running the same test, just with different labels), and they should both run in | ||
the neighborhood of 3.5 times slower than addition2 and addition3." | ||
EOD |
This file contains 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 characters