asymptotic 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/asymptotic.gemspec +1 -0
- data/lib/asymptotic.rb +1 -0
- data/lib/asymptotic/graph.rb +14 -16
- data/lib/asymptotic/version.rb +1 -1
- metadata +17 -1
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
|
-
|
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
|
-
|
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/
|
46
|
+
![](http://i.imgur.com/sOYTOWh.png)
|
47
47
|
|
48
48
|
## Contributing
|
49
49
|
|
data/asymptotic.gemspec
CHANGED
data/lib/asymptotic.rb
CHANGED
data/lib/asymptotic/graph.rb
CHANGED
@@ -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 "
|
13
|
+
plot.title "Average Runtime Analysis of #{@problem} (#{`ruby -v`.split(' (').first})"
|
14
14
|
plot.xlabel "Input size"
|
15
|
-
plot.ylabel "
|
16
|
-
|
15
|
+
plot.ylabel "Average time taken in seconds (ran #{@attempt} times)"
|
17
16
|
|
18
17
|
@algorithm_hash.each do |name, function_hash|
|
19
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
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
|
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
|
-
|
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)
|
data/lib/asymptotic/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: asymptotic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
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:
|