exoteric 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -8,3 +8,8 @@ end
8
8
 
9
9
  task :test => :spec
10
10
  task :default => :test
11
+
12
+ desc "Run benchmarks"
13
+ task :benchmark do
14
+ load File.expand_path("../spec/counters_benchmark.rb", __FILE__)
15
+ end
data/config.ru ADDED
@@ -0,0 +1,4 @@
1
+ # -*- ruby -*-
2
+ require 'exoteric/api'
3
+
4
+ run Exoteric::API
@@ -1,5 +1,7 @@
1
1
  require 'json'
2
2
  require 'rest_client'
3
+ require 'thread'
4
+ require 'timeout'
3
5
 
4
6
  module Exoteric
5
7
  class Counter
@@ -23,11 +25,24 @@ module Exoteric
23
25
  if counters.size == 0 || counters.first == :all
24
26
  counters = self.class.counters
25
27
  end
28
+
29
+ res = {}
30
+ sem = Mutex.new
31
+ threads = []
26
32
 
27
- counters.inject({}) do |res, name|
28
- res[name] = send("#{name}_count")
29
- res
33
+ counters.each do |name|
34
+ threads << Thread.new do
35
+ sem.synchronize { res[name] = send("#{name}_count") }
36
+ end
30
37
  end
38
+
39
+ Timeout.timeout(10) do
40
+ threads.each(&:join)
41
+ end
42
+ rescue Timeout::Error
43
+ # nothing to do...
44
+ ensure
45
+ return res
31
46
  end
32
47
  end
33
48
  end
@@ -1,5 +1,5 @@
1
1
  module Exoteric
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -0,0 +1,10 @@
1
+ require 'exoteric'
2
+ require 'benchmark'
3
+
4
+ $counter = Exoteric::Counter.new(:url => "http://areyoufuckingcoding.me/")
5
+
6
+ n = 5
7
+
8
+ Benchmark.bm do |bm|
9
+ bm.report("Counter#count") { n.times { |x| $counter.count(:twitter, :plusone, :facebook) }}
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exoteric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-27 00:00:00.000000000 Z
12
+ date: 2012-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -136,6 +136,7 @@ files:
136
136
  - LICENSE
137
137
  - README.md
138
138
  - Rakefile
139
+ - config.ru
139
140
  - exoteric.gemspec
140
141
  - lib/exoteric.rb
141
142
  - lib/exoteric/api.rb
@@ -147,6 +148,7 @@ files:
147
148
  - lib/exoteric/version.rb
148
149
  - spec/api_spec.rb
149
150
  - spec/counter_spec.rb
151
+ - spec/counters_benchmark.rb
150
152
  - spec/facebook_counter_spec.rb
151
153
  - spec/github_counter_spec.rb
152
154
  - spec/google_plus_counter_spec.rb
@@ -180,6 +182,7 @@ summary: Exoteric gives you page statistics from the most popular social network
180
182
  test_files:
181
183
  - spec/api_spec.rb
182
184
  - spec/counter_spec.rb
185
+ - spec/counters_benchmark.rb
183
186
  - spec/facebook_counter_spec.rb
184
187
  - spec/github_counter_spec.rb
185
188
  - spec/google_plus_counter_spec.rb