asymptotic 0.0.3 → 0.0.5

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.
data/README.md CHANGED
@@ -23,13 +23,13 @@ require 'asymptotic'
23
23
 
24
24
  Asymptotic::Graph::plot("Data-Structure Element Retrieval Methods",
25
25
 
26
- check_if_element_in_array: {
26
+ "Checking if an element is in an array" => {
27
27
  function: ->(shuffled_array){ shuffled_array.include? 1 },
28
28
  input_seeds: (1..1000),
29
29
  input_function: ->(limit){ (1..limit*1000).to_a.shuffle }
30
30
  },
31
31
 
32
- check_if_key_in_hash: {
32
+ "Checking if a key is in a hash" => {
33
33
  function: ->(hash){ hash.has_key? 'my key' },
34
34
  input_seeds: (1..1000),
35
35
  input_function: ->(limit){
@@ -43,7 +43,7 @@ Asymptotic::Graph::plot("Data-Structure Element Retrieval Methods",
43
43
  )
44
44
 
45
45
  ```
46
- ![](http://i.imgur.com/6PN7jCy.png)
46
+ ![](http://i.imgur.com/sOYTOWh.png)
47
47
 
48
48
  ## Contributing
49
49
 
@@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
 
24
24
  spec.add_dependency "colored"
25
+ spec.add_dependency "peach"
25
26
  spec.add_dependency "gnuplot"
26
27
  end
@@ -3,6 +3,7 @@ require "asymptotic/graph"
3
3
 
4
4
  require "benchmark"
5
5
  require "colored"
6
+ require "peach"
6
7
  require "gnuplot"
7
8
 
8
9
  module Asymptotic
@@ -10,28 +10,27 @@ module Asymptotic
10
10
  def plot
11
11
  Gnuplot.open do |gnuplot|
12
12
  Gnuplot::Plot.new(gnuplot) do |plot|
13
- plot.title "Asymptotic Analysis of #{@problem} (#{`ruby -v`.split(' (').first})"
13
+ plot.title "Average Runtime Analysis of #{@problem} (#{`ruby -v`.split(' (').first})"
14
14
  plot.xlabel "Input size"
15
- plot.ylabel "Time taken in seconds"
16
-
15
+ plot.ylabel "Average time taken in seconds (ran #{@attempt} times)"
17
16
 
18
17
  @algorithm_hash.each do |name, function_hash|
19
- puts "\nRunning benchmarks on: #{name}".green
20
- seeds = function_hash[:input_seeds]
18
+ seeds = function_hash[:input_seeds].to_a.shuffle
21
19
  input_generation_function = function_hash[:input_function]
22
20
  function = function_hash[:function]
23
- sizes = []
24
- runtimes = seeds.map do |seed|
25
- size = 0
21
+ puts "\nGenerating inputs...".red
22
+ inputs = seeds.pmap(8, &input_generation_function)
23
+ sizes = inputs.pmap(8, &:size)
24
+
25
+ puts "\nRunning benchmarks on: #{name}".green
26
+ runtimes = inputs.map do |input|
27
+
28
+ GC.disable
26
29
  times_taken = ([0] * @attempts).map do
27
- input = input_generation_function.(seed)
28
- size = input.size
29
- GC.disable
30
- time_taken = Benchmark.realtime { function[input] }
31
- GC.enable
32
- time_taken
30
+ Benchmark.realtime { function[input] }
33
31
  end
34
- sizes << size
32
+ GC.enable
33
+
35
34
  print '.'.yellow
36
35
  average_time_taken = times_taken.inject(:+) / @attempts.to_f
37
36
  end
@@ -45,7 +44,6 @@ module Asymptotic
45
44
  end
46
45
  end
47
46
  end
48
-
49
47
  end
50
48
 
51
49
  def self.plot(*args)
@@ -1,3 +1,3 @@
1
1
  module Asymptotic
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: asymptotic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Aaron Cronin
@@ -59,6 +59,22 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  none: false
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ none: false
69
+ name: peach
70
+ type: :runtime
71
+ prerelease: false
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ none: false
62
78
  - !ruby/object:Gem::Dependency
63
79
  version_requirements: !ruby/object:Gem::Requirement
64
80
  requirements: