Skip to content

Commit 8743b0d

Browse files
committed
Update readme and gitignore files. README has better usage examples and links to acks.
1 parent a5daf85 commit 8743b0d

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ build/
2828

2929
# for a library or gem, you might want to ignore these files since the code is
3030
# intended to run in multiple environments; otherwise, check them in:
31-
# Gemfile.lock
31+
Gemfile.lock
3232
# .ruby-version
3333
# .ruby-gemset
3434

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
# benchmark-plot
2+
23
A Ruby benchmark extension to allow comparative plotting of benchmarks.
34

5+
# Usage
6+
7+
This gem is mainly useful for benchmarking code over a number of inputs. This input should be supplied in the form of an object capable of calling `#each`.
8+
9+
Sample benchmarking script:
10+
11+
``` ruby
12+
require 'benchmark/plot'
13+
14+
class TestArray
15+
attr_reader :arr
16+
17+
def initialize arr
18+
@arr = arr
19+
end
20+
21+
def to_s
22+
@arr.size.to_s
23+
end
24+
end
25+
26+
test_data = [5, 25, 50, 75, 100, 125, 150, 175, 200,250,300]
27+
test_data.map! {|e| TestArray.new(Array.new(e) {|i| i}) }
28+
29+
Benchmark.plot(test_data) do |x|
30+
x.report("map.flatten") do |data|
31+
data.arr.map { [nil] }.flatten
32+
end
33+
34+
x.report("flat_map") do |data|
35+
data.arr.flat_map { [nil] }
36+
end
37+
end
38+
```
39+
40+
Output:
41+
42+
![Benchmarks](examples/mapflat_vs_flat_map/benchmark_plot_graph.png)
43+
444
# Acknowledgements
545

6-
@tgxworld for providing the co-working space during the Open Source Breakfast Hack during Red Dot Ruby Conf 2016 where this gem was built.
46+
[@tgxworld](https://github.com/tgxworld) for providing the co-working space during the Open Source Breakfast Hack during Red Dot Ruby Conference 2016 where this gem was built.

0 commit comments

Comments
 (0)