benchmark-bigo 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ require "minitest/autorun"
2
+ require "benchmark/bigo"
3
+
4
+ class TestChart < MiniTest::Test
5
+
6
+ def setup
7
+ @data = [
8
+ {:name=>"#foo", :data=>{1000=>0.4615925958419669, 2000=>0.46020338479480843, 3000=>0.49106768186885136}},
9
+ {:name=>"#bar", :data=>{1000=>2.869082276950677, 2000=>5.110045297799111, 3000=>7.439106136103487}},
10
+ {:name=>"#baz", :data=>{1000=>176.5676126850217, 2000=>349.88823646078873, 3000=>541.7084661739613}}]
11
+ @sizes = [1000,2000,3000]
12
+
13
+ @chart = Benchmark::BigO::Chart.new @data, @sizes
14
+ end
15
+
16
+ def test_initialize
17
+ assert_equal 1000, @chart.sample_size
18
+ end
19
+
20
+ def test_generate
21
+ generate = [{:name=>"Growth Chart", :data=>[{:name=>"#foo", :data=>{1000=>0.4615925958419669, 2000=>0.46020338479480843, 3000=>0.49106768186885136}}, {:name=>"#bar", :data=>{1000=>2.869082276950677, 2000=>5.110045297799111, 3000=>7.439106136103487}}, {:name=>"#baz", :data=>{1000=>176.5676126850217, 2000=>349.88823646078873, 3000=>541.7084661739613}}], :opts=>{:discrete=>true, :width=>"800px", :height=>"500px", :min=>0, :max=>651, :library=>{:colors=>["#f0662d", "#8062a6", "#7bc545", "#0883b2", "#ffaa00", "#00c7c3"], :xAxis=>{:type=>"linear", :title=>{:text=>"Size"}}, :yAxis=>{:type=>"linear", :title=>{:text=>"Microseconds per Iteration"}}}}}]
22
+
23
+ assert_equal generate, @chart.generate
24
+
25
+ generate_and_compare = [{:name=>"Growth Chart", :data=>[{:name=>"#foo", :data=>{1000=>0.4615925958419669, 2000=>0.46020338479480843, 3000=>0.49106768186885136}}, {:name=>"#bar", :data=>{1000=>2.869082276950677, 2000=>5.110045297799111, 3000=>7.439106136103487}}, {:name=>"#baz", :data=>{1000=>176.5676126850217, 2000=>349.88823646078873, 3000=>541.7084661739613}}], :opts=>{:discrete=>true, :width=>"800px", :height=>"500px", :min=>0, :max=>651, :library=>{:colors=>["#f0662d", "#8062a6", "#7bc545", "#0883b2", "#ffaa00", "#00c7c3"], :xAxis=>{:type=>"linear", :title=>{:text=>"Size"}}, :yAxis=>{:type=>"linear", :title=>{:text=>"Microseconds per Iteration"}}}}}, {:name=>"#foo", :data=>[{:name=>"#foo", :data=>{1000=>0.4615925958419669, 2000=>0.46020338479480843, 3000=>0.49106768186885136}}, {:name=>"const", :data=>{1000=>0.4615925958419669, 2000=>0.4615925958419669, 3000=>0.4615925958419669}}, {:name=>"log n", :data=>{1000=>0.4615925958419669, 2000=>0.5079103348835778, 3000=>0.5350044753411086}}, {:name=>"n", :data=>{1000=>0.4615925958419669, 2000=>0.9231851916839338, 3000=>1.3847777875259006}}, {:name=>"n log n", :data=>{1000=>0.46159259584196694, 2000=>1.015820669767156, 3000=>1.6050134260233262}}, {:name=>"n squared", :data=>{1000=>0.4615925958419669, 2000=>1.8463703833678675, 3000=>4.1543333625777015}}], :opts=>{:discrete=>true, :width=>"800px", :height=>"500px", :min=>0, :max=>1, :library=>{:colors=>["#f0662d", "#8062a6", "#7bc545", "#0883b2", "#ffaa00", "#00c7c3"], :xAxis=>{:type=>"linear", :title=>{:text=>"Size"}}, :yAxis=>{:type=>"linear", :title=>{:text=>"Microseconds per Iteration"}}}}}, {:name=>"#bar", :data=>[{:name=>"#bar", :data=>{1000=>2.869082276950677, 2000=>5.110045297799111, 3000=>7.439106136103487}}, {:name=>"const", :data=>{1000=>2.869082276950677, 2000=>2.869082276950677, 3000=>2.869082276950677}}, {:name=>"log n", :data=>{1000=>2.869082276950677, 2000=>3.1569755520807, 3000=>3.3253823222415617}}, {:name=>"n", :data=>{1000=>2.869082276950677, 2000=>5.738164553901354, 3000=>8.60724683085203}}, {:name=>"n log n", :data=>{1000=>2.869082276950677, 2000=>6.313951104161399, 3000=>9.976146966724686}}, {:name=>"n squared", :data=>{1000=>2.869082276950677, 2000=>11.476329107802709, 3000=>25.821740492556092}}], :opts=>{:discrete=>true, :width=>"800px", :height=>"500px", :min=>2, :max=>9, :library=>{:colors=>["#f0662d", "#8062a6", "#7bc545", "#0883b2", "#ffaa00", "#00c7c3"], :xAxis=>{:type=>"linear", :title=>{:text=>"Size"}}, :yAxis=>{:type=>"linear", :title=>{:text=>"Microseconds per Iteration"}}}}}, {:name=>"#baz", :data=>[{:name=>"#baz", :data=>{1000=>176.5676126850217, 2000=>349.88823646078873, 3000=>541.7084661739613}}, {:name=>"const", :data=>{1000=>176.5676126850217, 2000=>176.5676126850217, 3000=>176.5676126850217}}, {:name=>"log n", :data=>{1000=>176.5676126850217, 2000=>194.28499524534556, 3000=>204.64899965406602}}, {:name=>"n", :data=>{1000=>176.5676126850217, 2000=>353.1352253700434, 3000=>529.7028380550651}}, {:name=>"n log n", :data=>{1000=>176.5676126850217, 2000=>388.56999049069105, 3000=>613.946998962198}}, {:name=>"n squared", :data=>{1000=>176.5676126850217, 2000=>706.2704507400867, 3000=>1589.108514165195}}], :opts=>{:discrete=>true, :width=>"800px", :height=>"500px", :min=>141, :max=>651, :library=>{:colors=>["#f0662d", "#8062a6", "#7bc545", "#0883b2", "#ffaa00", "#00c7c3"], :xAxis=>{:type=>"linear", :title=>{:text=>"Size"}}, :yAxis=>{:type=>"linear", :title=>{:text=>"Microseconds per Iteration"}}}}}]
26
+
27
+ assert_equal generate_and_compare, @chart.generate(:compare => true)
28
+ end
29
+
30
+ def test_opts_for
31
+
32
+ opts = {:discrete=>true, :width=>"800px", :height=>"500px", :min=>0, :max=>4, :library=>{:colors=>["#f0662d", "#8062a6", "#7bc545", "#0883b2", "#ffaa00", "#00c7c3"], :xAxis=>{:type=>"linear", :title=>{:text=>"Size"}}, :yAxis=>{:type=>"linear", :title=>{:text=>"Microseconds per Iteration"}}}}
33
+
34
+ assert_equal opts, @chart.opts_for([{:data => {1=> 1, 2=> 2, 3=> 3}}])
35
+
36
+ assert_equal opts, @chart.opts_for({:data => {1=> 1, 2=> 2, 3=> 3}})
37
+
38
+ assert_equal opts, @chart.opts_for([{:data => {1=> 1, 2=> 2, 3=> 3}}, {:data => { 1=> 1, 2=> 2, 3=> 3}}])
39
+ end
40
+
41
+ def test_comparison_for
42
+
43
+ comparison = [{:data=>{1000=>1, 2000=>2, 3000=>3}}, {:name=>"const", :data=>{1000=>1.0, 2000=>1.0, 3000=>1.0}}, {:name=>"log n", :data=>{1000=>1.0, 2000=>1.1003433318879936, 3000=>1.1590404182398875}}, {:name=>"n", :data=>{1000=>1.0, 2000=>2.0, 3000=>3.0}}, {:name=>"n log n", :data=>{1000=>1.0, 2000=>2.200686663775987, 3000=>3.4771212547196626}}, {:name=>"n squared", :data=>{1000=>1.0, 2000=>4.0, 3000=>9.0}}]
44
+
45
+ assert_equal comparison, @chart.comparison_for({:data => {1000 => 1, 2000 => 2, 3000 => 3}})
46
+
47
+ end
48
+
49
+ def test_const_type
50
+ assert Benchmark::BigO::Chart::TYPES.include? :const
51
+
52
+ assert_equal "const", @chart.title_for(:const)
53
+ assert_equal 10, @chart.factor_for(:const, 10)
54
+ assert_equal 10, @chart.data_generator(:const, @sizes.last, 10)
55
+ end
56
+
57
+ def test_logn_type
58
+ assert Benchmark::BigO::Chart::TYPES.include? :logn
59
+
60
+ assert_equal "log n", @chart.title_for(:logn)
61
+ assert_equal 10/3.0, @chart.factor_for(:logn, 10)
62
+ assert_equal (Math.log10(3000) * 10/3.0), @chart.data_generator(:logn, @sizes.last, 10)
63
+ end
64
+
65
+ def test_n_type
66
+ assert Benchmark::BigO::Chart::TYPES.include? :n
67
+
68
+ assert_equal "n", @chart.title_for(:n)
69
+ assert_equal 0.01, @chart.factor_for(:n, 10)
70
+ assert_equal 30, @chart.data_generator(:n, @sizes.last, 10)
71
+ end
72
+
73
+ def test_nlogn_type
74
+ assert Benchmark::BigO::Chart::TYPES.include? :nlogn
75
+
76
+ assert_equal "n log n", @chart.title_for(:nlogn)
77
+ assert_equal "0.003333", sprintf("%0.6f", @chart.factor_for(:nlogn, 10))
78
+ assert_equal "34.771213", sprintf("%0.6f", @chart.data_generator(:nlogn, @sizes.last, 10))
79
+ end
80
+
81
+ def test_n_sq_type
82
+ assert Benchmark::BigO::Chart::TYPES.include? :n_sq
83
+
84
+ assert_equal "n squared", @chart.title_for(:n_sq)
85
+ assert_equal "0.000010", sprintf("%0.6f", @chart.factor_for(:n_sq, 10))
86
+ assert_equal "90.000000", sprintf("%0.6f", @chart.data_generator(:n_sq, @sizes.last, 10))
87
+ end
88
+
89
+ end
@@ -0,0 +1,52 @@
1
+ require "minitest/autorun"
2
+ require "benchmark/bigo"
3
+
4
+ class TestTermPlot < MiniTest::Test
5
+
6
+ def setup
7
+ @data = [
8
+ {:name=>"#foo", :data=>{1000=>50.46159, 2000=>75.460203, 3000=>125.4910676}},
9
+ {:name=>"#bar", :data=>{1000=>100.869, 2000=>200.110, 3000=>300.439}},
10
+ {:name=>"#baz", :data=>{1000=>176, 2000=>349, 3000=>541}}]
11
+ @sizes = [1000,2000,3000]
12
+
13
+ @termplot = Benchmark::BigO::TermPlot.new @data, @sizes
14
+ end
15
+
16
+ def test_title_for
17
+
18
+ assert_equal "#foo", @termplot.title_for(0)
19
+ assert_equal "#bar", @termplot.title_for(1)
20
+ assert_equal "#baz", @termplot.title_for(2)
21
+ end
22
+
23
+ def test_dat_lines
24
+
25
+ lines = ["1000 50.46159 100.869 176",
26
+ "2000 75.460203 200.11 349",
27
+ "3000 125.4910676 300.439 541"]
28
+
29
+ assert_equal lines, @termplot.dat_lines
30
+ end
31
+
32
+ def test_commands
33
+
34
+ commands = [
35
+ "set term dumb",
36
+ "set key top left vertical inside width 3",
37
+ "plot '/var/folders/zj/sjlr64rx0933f09kk3hntmnc0000gq/T/termplot20141103-11019-1l0jv3n' using 1:2 title '#foo' with lines,\\",
38
+ "\"\" using 1:3 title '#bar' with lines,\\",
39
+ "\"\" using 1:4 title '#baz' with lines"]
40
+
41
+ assert_equal 5, @termplot.commands.length
42
+ assert_equal commands[0], @termplot.commands[0]
43
+ assert_equal commands[1], @termplot.commands[1]
44
+
45
+ (2...3).each do |i|
46
+ assert @termplot.commands[i].include? "using 1:#{i} title '#{@data[i-2][:name]}'"
47
+ end
48
+
49
+ end
50
+
51
+
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark-bigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davy Stevenson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -90,11 +90,15 @@ extra_rdoc_files:
90
90
  files:
91
91
  - README.md
92
92
  - lib/benchmark/bigo.rb
93
+ - lib/benchmark/bigo/chart.rb
93
94
  - lib/benchmark/bigo/job.rb
94
95
  - lib/benchmark/bigo/report.rb
95
96
  - lib/benchmark/bigo/templates/chart.erb
97
+ - lib/benchmark/bigo/termplot.rb
96
98
  - lib/benchmark/bigo/version.rb
97
99
  - test/benchmark/test_bigo.rb
100
+ - test/benchmark/test_chart.rb
101
+ - test/benchmark/test_termplot.rb
98
102
  homepage: http://github.com/davy/benchmark-bigo
99
103
  licenses:
100
104
  - MIT
@@ -123,3 +127,5 @@ specification_version: 4
123
127
  summary: Benchmark objects to help calculate Big O behavior
124
128
  test_files:
125
129
  - test/benchmark/test_bigo.rb
130
+ - test/benchmark/test_chart.rb
131
+ - test/benchmark/test_termplot.rb