asymptotic 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asymptotic.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aaron Cronin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Asymptotic
2
+
3
+ Create runtime-analysis graphs with minimal effort.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'asymptotic'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install asymptotic
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'asymptotic'
23
+
24
+ Asymptotic::Graph::plot("Data-Structure Element Retrieval Methods",
25
+
26
+ check_if_element_in_array: {
27
+ function: ->(shuffled_array) { shuffled_array.include? 1 },
28
+ input_seeds: (1..1000),
29
+ input_function: ->(limit){ (1..limit*1000).to_a.shuffle }
30
+ },
31
+
32
+ check_if_key_in_hash: {
33
+ function: ->(hash) { hash.has_key? 'my key' },
34
+ input_seeds: (1..1000),
35
+ input_function: ->(limit){
36
+ hash = {}.tap { |h|
37
+ (limit*1000).times { |num| h[num] = 'some val' }
38
+ h['my key'] = 'my val'
39
+ }
40
+ }
41
+ }
42
+
43
+ )
44
+
45
+ ```
46
+ ![](http://i.imgur.com/oZ4VpMx.png)
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asymptotic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asymptotic"
8
+ spec.version = Asymptotic::VERSION
9
+ spec.authors = ["Aaron Cronin"]
10
+ spec.email = ["cronin@include.cat"]
11
+ spec.description = %q{Toolkit for asymptotic analysis of functions}
12
+ spec.summary = %q{Toolkit for asymptotic analysis of functions}
13
+ spec.homepage = "https://github.com/cronin101/asymptotic.gem"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "colored"
25
+ spec.add_dependency "gnuplot"
26
+ end
data/lib/asymptotic.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "asymptotic/version"
2
+ require "asymptotic/graph"
3
+
4
+ require "benchmark"
5
+ require "colored"
6
+ require "gnuplot"
7
+
8
+ module Asymptotic
9
+ end
@@ -0,0 +1,51 @@
1
+ module Asymptotic
2
+ class Graph
3
+
4
+ def initialize(problem, algorithm_hash)
5
+ @problem = problem
6
+ @algorithm_hash = algorithm_hash
7
+ end
8
+
9
+ def plot
10
+ Gnuplot.open do |gnuplot|
11
+ Gnuplot::Plot.new(gnuplot) do |plot|
12
+ plot.title "Asymptotic Analysis of #{@problem} (#{`ruby -v`.split(' (').first})"
13
+ plot.xlabel "Input size"
14
+ plot.ylabel "Time taken"
15
+
16
+
17
+ @algorithm_hash.each do |name, function_hash|
18
+ puts "\nRunning benchmarks on: #{name}".green
19
+ seeds = function_hash[:input_seeds]
20
+ input_generation_function = function_hash[:input_function]
21
+ function = function_hash[:function]
22
+ sizes = []
23
+ runtimes = seeds.map do |seed|
24
+ input = input_generation_function.(seed)
25
+ sizes << input.size
26
+ print '.'.yellow
27
+ GC.disable
28
+ time_taken = Benchmark.realtime { function[input] }
29
+ GC.enable
30
+ time_taken
31
+ end
32
+
33
+ points = [sizes, runtimes]
34
+ plot.data << Gnuplot::DataSet.new(points) do |set|
35
+ set.with = "linespoints"
36
+ set.title = name
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ def self.plot(*args)
46
+ self.new(*args).plot
47
+ end
48
+
49
+ end
50
+ end
51
+
@@ -0,0 +1,3 @@
1
+ module Asymptotic
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asymptotic
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Cronin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ none: false
21
+ name: bundler
22
+ type: :development
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.3'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ none: false
37
+ name: rake
38
+ type: :development
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ none: false
53
+ name: colored
54
+ type: :runtime
55
+ prerelease: false
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
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: gnuplot
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
78
+ description: Toolkit for asymptotic analysis of functions
79
+ email:
80
+ - cronin@include.cat
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - asymptotic.gemspec
91
+ - lib/asymptotic.rb
92
+ - lib/asymptotic/graph.rb
93
+ - lib/asymptotic/version.rb
94
+ homepage: https://github.com/cronin101/asymptotic.gem
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ none: false
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ none: false
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.23
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Toolkit for asymptotic analysis of functions
119
+ test_files: []