stoppur 0.0.2
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.
- checksums.yaml +7 -0
- data/ext/stoppur/extconf.rb +3 -0
- data/ext/stoppur/time/c_clock.c +36 -0
- data/lib/stoppur.rb +20 -0
- data/lib/stoppur/clock.rb +14 -0
- data/lib/stoppur/stopwatch.rb +29 -0
- data/lib/stoppur/time/java_clock.rb +11 -0
- data/lib/stoppur/time/naive_clock.rb +11 -0
- data/lib/stoppur/time/process_clock.rb +11 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d0579adcbf4cd740c3686a3a19ebfb1391875de
|
4
|
+
data.tar.gz: cfd0a382122cb6c4d2671c55f2dcf7b5baa52f13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e709a0fbed547640d491ff0d57c3e94947984b8c7f8643faaba583abeb58474b1ae7d7fb0d88c47e9a2c4ffe94e759ea21b660e310587c63d32cdd74187ddd7b
|
7
|
+
data.tar.gz: 567e720cc44029cb369b653d97f85297a03d183c5a75cf21cdbba171c6361d870a4f0d4a7ef7e77d90d8d13802237b6e8cd73986502c177a066926ad415e149b
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
#ifdef __MACH__
|
4
|
+
#include <mach/clock.h>
|
5
|
+
#include <mach/mach.h>
|
6
|
+
#else
|
7
|
+
#include <time.h>
|
8
|
+
#endif
|
9
|
+
|
10
|
+
void Init_stoppur();
|
11
|
+
VALUE method_time(VALUE self);
|
12
|
+
|
13
|
+
VALUE Stoppur = Qnil;
|
14
|
+
VALUE Time = Qnil;
|
15
|
+
VALUE CClock = Qnil;
|
16
|
+
|
17
|
+
void Init_c_clock() {
|
18
|
+
Stoppur = rb_define_module("Stoppur");
|
19
|
+
Time = rb_define_module_under(Stoppur, "Time");
|
20
|
+
CClock = rb_define_class_under(Time, "CClock", rb_cObject);
|
21
|
+
rb_define_method(CClock, "time", method_time, 0);
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE method_time(VALUE self) {
|
25
|
+
#ifdef __MACH__
|
26
|
+
mach_timespec_t ts;
|
27
|
+
clock_serv_t cclock;
|
28
|
+
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
29
|
+
clock_get_time(cclock, &ts);
|
30
|
+
mach_port_deallocate(mach_task_self(), cclock);
|
31
|
+
#else
|
32
|
+
struct timespec ts;
|
33
|
+
clock_gettime(CLOCK_REALTIME, &ts);
|
34
|
+
#endif
|
35
|
+
return DBL2NUM(ts.tv_sec + ts.tv_nsec / 1e9);
|
36
|
+
}
|
data/lib/stoppur.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'stoppur/clock'
|
4
|
+
require 'stoppur/stopwatch'
|
5
|
+
|
6
|
+
module Stoppur
|
7
|
+
def self.measure(&block)
|
8
|
+
stopwatch = start
|
9
|
+
block.call
|
10
|
+
stopwatch.elapsed
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.start
|
14
|
+
Stopwatch.new(DEFAULT_CLOCK).start
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
DEFAULT_CLOCK = Clock.new
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Stoppur
|
4
|
+
if Process.respond_to?(:clock_gettime)
|
5
|
+
require 'stoppur/time/process_clock'
|
6
|
+
Clock = Time::ProcessClock
|
7
|
+
elsif RUBY_PLATFORM == 'java'
|
8
|
+
require 'stoppur/time/java_clock'
|
9
|
+
Clock = Time::JavaClock
|
10
|
+
else
|
11
|
+
require 'stoppur/time/c_clock'
|
12
|
+
Clock = Time::CClock
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Stoppur
|
4
|
+
class Stopwatch
|
5
|
+
def initialize(clock)
|
6
|
+
@clock = clock
|
7
|
+
end
|
8
|
+
|
9
|
+
def start
|
10
|
+
raise AlreadyStartedError if started?
|
11
|
+
@start_time = @clock.time
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def elapsed
|
16
|
+
raise NotStartedError unless started?
|
17
|
+
@clock.time - @start_time
|
18
|
+
end
|
19
|
+
|
20
|
+
AlreadyStartedError = Class.new(StandardError)
|
21
|
+
NotStartedError = Class.new(StandardError)
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def started?
|
26
|
+
@start_time
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stoppur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joel Segerlind
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.7'
|
69
|
+
description: Simple time measurement, with monotonic clocks
|
70
|
+
email: joel@jowl.se
|
71
|
+
executables: []
|
72
|
+
extensions:
|
73
|
+
- ext/stoppur/extconf.rb
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ext/stoppur/extconf.rb
|
77
|
+
- ext/stoppur/time/c_clock.c
|
78
|
+
- lib/stoppur.rb
|
79
|
+
- lib/stoppur/clock.rb
|
80
|
+
- lib/stoppur/stopwatch.rb
|
81
|
+
- lib/stoppur/time/java_clock.rb
|
82
|
+
- lib/stoppur/time/naive_clock.rb
|
83
|
+
- lib/stoppur/time/process_clock.rb
|
84
|
+
homepage: https://github.com/jowl/stoppur
|
85
|
+
licenses:
|
86
|
+
- Apache License 2.0
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.4
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Simple time measurement
|
108
|
+
test_files: []
|