asymptotic 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Asymptotic
1
+ # asymptotic.gem
2
2
 
3
3
  Create runtime-analysis graphs with minimal effort.
4
4
 
@@ -24,13 +24,13 @@ require 'asymptotic'
24
24
  Asymptotic::Graph::plot("Data-Structure Element Retrieval Methods",
25
25
 
26
26
  check_if_element_in_array: {
27
- function: ->(shuffled_array) { shuffled_array.include? 1 },
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
32
  check_if_key_in_hash: {
33
- function: ->(hash) { hash.has_key? 'my key' },
33
+ function: ->(hash){ hash.has_key? 'my key' },
34
34
  input_seeds: (1..1000),
35
35
  input_function: ->(limit){
36
36
  hash = {}.tap { |h|
@@ -43,7 +43,7 @@ Asymptotic::Graph::plot("Data-Structure Element Retrieval Methods",
43
43
  )
44
44
 
45
45
  ```
46
- ![](http://i.imgur.com/oZ4VpMx.png)
46
+ ![](http://i.imgur.com/6PN7jCy.png)
47
47
 
48
48
  ## Contributing
49
49
 
@@ -1,7 +1,8 @@
1
1
  module Asymptotic
2
2
  class Graph
3
3
 
4
- def initialize(problem, algorithm_hash)
4
+ def initialize(attempts = 5, problem, algorithm_hash)
5
+ @attempts = attempts
5
6
  @problem = problem
6
7
  @algorithm_hash = algorithm_hash
7
8
  end
@@ -11,7 +12,7 @@ module Asymptotic
11
12
  Gnuplot::Plot.new(gnuplot) do |plot|
12
13
  plot.title "Asymptotic Analysis of #{@problem} (#{`ruby -v`.split(' (').first})"
13
14
  plot.xlabel "Input size"
14
- plot.ylabel "Time taken"
15
+ plot.ylabel "Time taken in seconds"
15
16
 
16
17
 
17
18
  @algorithm_hash.each do |name, function_hash|
@@ -21,13 +22,18 @@ module Asymptotic
21
22
  function = function_hash[:function]
22
23
  sizes = []
23
24
  runtimes = seeds.map do |seed|
24
- input = input_generation_function.(seed)
25
- sizes << input.size
25
+ size = 0
26
+ 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
33
+ end
34
+ sizes << size
26
35
  print '.'.yellow
27
- GC.disable
28
- time_taken = Benchmark.realtime { function[input] }
29
- GC.enable
30
- time_taken
36
+ average_time_taken = times_taken.inject(:+) / @attempts.to_f
31
37
  end
32
38
 
33
39
  points = [sizes, runtimes]
@@ -1,3 +1,3 @@
1
1
  module Asymptotic
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Aaron Cronin