Skip to content

Commit

Permalink
Rename 'complexity' for 'big-o'.
Browse files Browse the repository at this point in the history
The name was somewhat too common :).
  • Loading branch information
kouno committed Jul 25, 2012
1 parent 31f0db0 commit 34026f0
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 37 deletions.
16 changes: 11 additions & 5 deletions README.md
@@ -1,6 +1,6 @@
# Complexity
# Big-O

Complexity is a gem which analyse an anonymous function and verify that it follow a specific pattern
Big-O is a gem which analyse an anonymous function and verify that it follow a specific pattern
in its memory usage or its execution time.

## Requirements
Expand All @@ -14,7 +14,7 @@ This gem has been tested on Mac OS X, using Ruby 1.9.3.
Checking if a function has a complexity of O(n) is as simple as this:

```ruby
time_complexity = Complexity::TimeComplexity({
time_complexity = BigO::TimeComplexity({
:fn => lambda { |n| do_something_time_consuming(n) },
:level => lambda { |n| n }
})
Expand All @@ -24,8 +24,8 @@ time_complexity.process # => true if it is growing in time constantly.
It is also possible to define multiple configuration parameters:

```ruby
space_complexity = Complexity::SpaceComplexity({
:fn => lambda { |n| do_something_time_consuming(n) }
space_complexity = BigO::SpaceComplexity({
:fn => lambda { |n| do_something_space_consuming(n) }
:level => lambda { |n| n },
:range => 1..20, # value of n
:timeout => 10, # time in seconds
Expand All @@ -35,6 +35,12 @@ space_complexity = Complexity::SpaceComplexity({
})
```

## Reference

You may want to read more on the subject by reading:
* http://en.wikipedia.org/wiki/Analysis_of_algorithms
* http://en.wikipedia.org/wiki/Big_O_notation

## License

Complexity is licensed under the MIT License - see the LICENSE file for details
Empty file added complexity.gemspec
Empty file.
1 change: 1 addition & 0 deletions lib/big-o-matchers.rb
@@ -0,0 +1 @@
require 'big-o/matchers/match_complexity_level'
7 changes: 7 additions & 0 deletions lib/big-o.rb
@@ -0,0 +1,7 @@
require 'timeout'
require 'benchmark'

require 'big-o/complexity_base'
require 'big-o/time_complexity'
require 'big-o/space_complexity'
require 'big-o/exceptions'
@@ -1,4 +1,4 @@
module Complexity
module BigO
# ComplexityBase regroup every process common to the benchmarking of a function.
module ComplexityBase

Expand Down
2 changes: 1 addition & 1 deletion lib/complexity/exceptions.rb → lib/big-o/exceptions.rb
@@ -1,4 +1,4 @@
module Complexity
module BigO
# The function could not be run more than X times (where X is a configurable value).
#
# This exception happens if the function is too slow to run, or if the timeout is too short.
Expand Down
@@ -1,4 +1,4 @@
module Complexity
module BigO
# Measure space complexity.
class SpaceComplexity
include ComplexityBase
Expand Down
@@ -1,4 +1,4 @@
module Complexity
module BigO
# Measure time complexity.
class TimeComplexity
include ComplexityBase
Expand Down
1 change: 0 additions & 1 deletion lib/complexity-matchers.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/complexity.rb

This file was deleted.

@@ -1,5 +1,5 @@
require 'spec_helper'
include Complexity
include BigO

describe ComplexityBase do
before :all do
Expand Down
@@ -1,5 +1,5 @@
require 'spec_helper'
include Complexity
include BigO

describe SpaceComplexity do
before :each do
Expand Down
@@ -1,5 +1,5 @@
require 'spec_helper'
include Complexity
include BigO

describe TimeComplexity do
before :each do
Expand Down
26 changes: 14 additions & 12 deletions spec/helpers/simulation.rb
@@ -1,16 +1,18 @@
module Helpers
ONE_KILO_OCTET = 'a' * 1024
module BigO
module Helpers
ONE_KILO_OCTET = 'a' * 1024

def simulate_utime_processing(seconds)
t0 = Process.times
begin
t1 = Process.times
end while (t1.utime - t0.utime) < seconds
end
def simulate_utime_processing(seconds)
t0 = Process.times
begin
t1 = Process.times
end while (t1.utime - t0.utime) < seconds
end

def simulate_memory_space(ko)
space = ONE_KILO_OCTET * ko
sleep(0.01)
space
def simulate_memory_space(ko)
space = ONE_KILO_OCTET * ko
sleep(0.01)
space
end
end
end
2 changes: 1 addition & 1 deletion spec/matchers/match_complexity_level_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
include Complexity
include BigO

describe 'match_complexity_level matcher' do
before :each do
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
@@ -1,8 +1,8 @@
require 'helpers/simulation'
require File.expand_path('../../lib/complexity.rb', __FILE__)
require File.expand_path('../../lib/complexity-matchers.rb', __FILE__)
require File.expand_path('../../lib/big-o.rb', __FILE__)
require File.expand_path('../../lib/big-o-matchers.rb', __FILE__)

RSpec.configure do |c|
c.include Helpers
c.include Complexity
c.include BigO
c.include BigO::Helpers
end

0 comments on commit 34026f0

Please sign in to comment.