fast-stats 1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ /* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */
2
+
3
+ /*
4
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions
9
+ * are met:
10
+ * 1. Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ * 3. The name of the author may not be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #ifdef LINUX
31
+
32
+ #include <sys/types.h>
33
+ #include <string.h>
34
+
35
+ /*
36
+ * Copy src to string dst of size siz. At most siz-1 characters
37
+ * will be copied. Always NUL terminates (unless siz == 0).
38
+ * Returns strlen(src); if retval >= siz, truncation occurred.
39
+ */
40
+ size_t strlcpy(dst, src, siz)
41
+ char *dst;
42
+ const char *src;
43
+ size_t siz;
44
+ {
45
+ register char *d = dst;
46
+ register const char *s = src;
47
+ register size_t n = siz;
48
+
49
+ /* Copy as many bytes as will fit */
50
+ if (n != 0 && --n != 0) {
51
+ do {
52
+ if ((*d++ = *s++) == 0)
53
+ break;
54
+ } while (--n != 0);
55
+ }
56
+
57
+ /* Not enough room in dst, add NUL and traverse rest of src */
58
+ if (n == 0) {
59
+ if (siz != 0)
60
+ *d = '\0'; /* NUL-terminate dst */
61
+ while (*s++)
62
+ ;
63
+ }
64
+
65
+ return(s - src - 1); /* count does not include NUL */
66
+ }
67
+
68
+ #endif
@@ -0,0 +1,17 @@
1
+ require './lib/stats/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "fast-stats"
5
+ s.version = StatsGem::VERSION
6
+ s.authors = ["Alan Pearson"]
7
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
8
+ s.extensions = ["ext/stats/extconf.rb"]
9
+ s.files = `git ls-files .`.split("\n")
10
+ s.files += `find ext -name *.c`.split("\n")
11
+ s.files += `find ext -name *.h`.split("\n")
12
+ s.require_paths = ["lib"]
13
+ s.test_files = `git ls-files spec examples`.split("\n")
14
+ s.required_ruby_version = ">= 1.9.3"
15
+ s.summary = "stats monitoring"
16
+ end
17
+
@@ -0,0 +1,3 @@
1
+ module StatsGem
2
+ VERSION = '1.7'
3
+ end
data/lib/stats.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "stats/stats"
2
+ require "stats/version"
3
+
4
+ class Stats
5
+ def self.version
6
+ StatsGem::VERSION
7
+ end
8
+ end
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stats'
4
+ require 'benchmark'
5
+
6
+ puts "version is #{Stats.version}"
7
+
8
+ puts "creating stats object"
9
+ s = Stats.new("rubytest")
10
+
11
+ result = 0
12
+ times = Benchmark.measure do
13
+ 10_000_000.times do |n|
14
+ result = result + n
15
+ end
16
+ end
17
+
18
+ puts "Baseline with no counter: time = #{times}"
19
+
20
+ result = 0
21
+ times = Benchmark.measure do
22
+ 10_000_000.times do |n|
23
+ s.inc("foo")
24
+ result = result + n
25
+ end
26
+ end
27
+
28
+ puts "Using Stats#inc: time = #{times}"
29
+
30
+ result = 0
31
+ ctr = s.get("bar")
32
+ times = Benchmark.measure do
33
+ 10_000_000.times do |n|
34
+ ctr.inc
35
+ result = result + n
36
+ end
37
+ end
38
+
39
+ puts "Using Counter#inc:. time = #{times}"
40
+
41
+
42
+ result = 0
43
+ times = Benchmark.measure do
44
+ 10_000_000.times do |n|
45
+ result = result + 1
46
+ end
47
+ end
48
+
49
+ puts "Ruby variable increment: time = #{times}"
50
+
51
+ result = 0
52
+ ctr = s.get("bazz")
53
+ times = Benchmark.measure do
54
+ 10_000_000.times do |n|
55
+ ctr.inc
56
+ end
57
+ end
58
+
59
+ puts "Counter increment: time = #{times}"
60
+
61
+
62
+
63
+ result = 0
64
+ timer = s.timer("timer")
65
+ times = Benchmark.measure do
66
+ 10_000_000.times do |n|
67
+ timer.enter
68
+ result = result + n
69
+ timer.exit
70
+ end
71
+ end
72
+
73
+ puts "Timer: time = #{times}"
74
+
75
+
76
+
77
+ result = 0
78
+ timer = s.timer("btimer")
79
+ times = Benchmark.measure do
80
+ 10_000_000.times do |n|
81
+ timer.time do
82
+ result = result + n
83
+ end
84
+ end
85
+ end
86
+
87
+ puts "Timer with block: time = #{times}"
88
+
89
+
90
+
91
+ result = 0
92
+ timer = s.get("rtimer")
93
+ times = Benchmark.measure do
94
+ 10_000_000.times do |n|
95
+ start = Time.now
96
+ result = result + n
97
+ timer.add(((Time.now.to_f - start.to_f) * 1000000).to_i)
98
+ end
99
+ end
100
+
101
+ puts "Ruby Timer: time = #{times}"
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stats'
4
+
5
+ puts "TEST STATS: version is #{Stats.version}"
6
+
7
+ s = Stats.new("rubytest")
8
+ ctr = s.get("ctr")
9
+ ctr.inc
10
+
11
+ puts "TEST STATS: OK"
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fast-stats
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.7'
5
+ platform: ruby
6
+ authors:
7
+ - Alan Pearson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions:
17
+ - ext/stats/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Makefile
21
+ - ext/stats/.gitignore
22
+ - ext/stats/extconf.rb
23
+ - ext/stats/stats-ruby.c
24
+ - fast-stats.gemspec
25
+ - lib/stats.rb
26
+ - lib/stats/version.rb
27
+ - test/benchmark_stats.rb
28
+ - test/test_stats.rb
29
+ - ext/stats/error.c
30
+ - ext/stats/hash.c
31
+ - ext/stats/lock.c
32
+ - ext/stats/mt19937.c
33
+ - ext/stats/semaphore.c
34
+ - ext/stats/shared_mem.c
35
+ - ext/stats/stats.c
36
+ - ext/stats/strlcat.c
37
+ - ext/stats/strlcpy.c
38
+ - ext/stats/mt19937.h
39
+ - ext/stats/stats/debug.h
40
+ - ext/stats/stats/error.h
41
+ - ext/stats/stats/hash.h
42
+ - ext/stats/stats/lock.h
43
+ - ext/stats/stats/omode.h
44
+ - ext/stats/stats/semaphore.h
45
+ - ext/stats/stats/shared_mem.h
46
+ - ext/stats/stats/stats.h
47
+ homepage:
48
+ licenses: []
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: 1.9.3
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.0.3
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: stats monitoring
70
+ test_files: []