benchmark_ext 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ #include <ruby.h>
2
+
3
+ VALUE bmm;
4
+
5
+ long bm_timestamp()
6
+ {
7
+ struct timeval tv;
8
+ gettimeofday(&tv, NULL);
9
+ return tv.tv_sec * 1000000 + tv.tv_usec;
10
+ }
11
+
12
+ double bm_tms_value(VALUE tms, const char *name)
13
+ {
14
+ return NUM2DBL(rb_funcall(tms, rb_intern(name), 0));
15
+ }
16
+
17
+ /* call-seq:
18
+ timestamp -> Float
19
+
20
+ Returns the current UNIX timestamp, as a Float.
21
+ */
22
+ VALUE bmm_timestamp(VALUE obj) {
23
+ return rb_float_new((double) bm_timestamp() / 1000000);
24
+ }
25
+
26
+ /* call-seq:
27
+ realtime {block} -> Float
28
+
29
+ Returns the elapsed real time used to execute the given block.
30
+ */
31
+ VALUE bmm_realtime(VALUE obj)
32
+ {
33
+ long t1, t2;
34
+
35
+ if (!rb_block_given_p())
36
+ {
37
+ rb_raise(rb_eArgError, "A block must be provided.");
38
+ }
39
+
40
+ t1 = bm_timestamp();
41
+ rb_yield(obj);
42
+ t2 = bm_timestamp();
43
+ return rb_float_new((double) (t2 - t1) / 1000000);
44
+ }
45
+
46
+ void Init_benchmark_ext() {
47
+ rb_require("benchmark");
48
+ bmm = rb_define_module("Benchmark");
49
+ rb_define_module_function(bmm, "timestamp", bmm_timestamp, 0);
50
+ rb_define_module_function(bmm, "realtime", bmm_realtime, 0);
51
+ }
@@ -0,0 +1,9 @@
1
+ require 'mkmf'
2
+
3
+ $CFLAGS << " -DRUBY19" if RUBY_VERSION >= '1.9.0'
4
+ $CFLAGS << " -DRUBY186" if RUBY_VERSION < '1.8.7'
5
+ $CFLAGS << " -Wall " unless RUBY_PLATFORM =~ /solaris/
6
+ $CFLAGS << ' -g -ggdb -rdynamic -O0 -DDEBUG' if ENV['DEBUG']
7
+ $CFLAGS << " -Wconversion -Wsign-compare -Wno-unused-parameter -Wwrite-strings -Wpointer-arith -fno-common -pedantic -Wno-long-long" if ENV['STRICT']
8
+ $CFLAGS << (ENV['CFLAGS'] || '')
9
+ create_makefile("benchmark_ext")
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benchmark_ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dimitrij Denissenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &21583000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *21583000
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake-compiler
27
+ requirement: &21579740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *21579740
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &21577480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21577480
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &21575560 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *21575560
58
+ description: Native implementation of Benchmark with much better performance.
59
+ email: dimitrij@blacksquaremedia.com
60
+ executables: []
61
+ extensions:
62
+ - ext/benchmark_ext/extconf.rb
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ext/benchmark_ext/extconf.rb
66
+ - ext/benchmark_ext/benchmark_ext.c
67
+ homepage: https://github.com/bsm/benchmark_ext
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.9.2
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.6
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.10
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Benchmark everything, just faster!
91
+ test_files: []