stoppur 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -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 +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4dad8eb05b7d6a6b312a929130ee531b1ae1ec91
|
4
|
+
data.tar.gz: dec8a3ad199cc44a66563b4e3aaa4bf4f5447ec9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8ae0ceebabd399468d96603ef4ab257765f94e1575194f9e7e1941dc012bc58f00202c17e23ad0315616e8f7497713f89c0602afdf0e56cf50cd5f19b2b0791
|
7
|
+
data.tar.gz: bb75aac2dff0b4c61818a10692dad50ebefd51d9d7a51bf8a92ab02c3e0fadb0cdbf6e324370c5ce83b47502a843fbeafc7a4e223978a082c8a965f724e58c5e
|
@@ -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,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stoppur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: java
|
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
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0.9'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '3.1'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.9'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.7'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
description: Simple time measurement, with monotonic clocks
|
70
|
+
email: joel@jowl.se
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ext/stoppur/time/c_clock.c
|
76
|
+
- lib/stoppur.rb
|
77
|
+
- lib/stoppur/clock.rb
|
78
|
+
- lib/stoppur/stopwatch.rb
|
79
|
+
- lib/stoppur/time/java_clock.rb
|
80
|
+
- lib/stoppur/time/naive_clock.rb
|
81
|
+
- lib/stoppur/time/process_clock.rb
|
82
|
+
homepage: https://github.com/jowl/stoppur
|
83
|
+
licenses:
|
84
|
+
- Apache License 2.0
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Simple time measurement
|
106
|
+
test_files: []
|