ticktok 0.1.0
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/README.md +66 -0
- data/lib/ticktok/version.rb +5 -0
- data/lib/ticktok.rb +60 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 125177ca8bc16964942ee6048b6faf7ee0724d807925a476fd02c1f69ac12063
|
|
4
|
+
data.tar.gz: 74bd4d419eb751f6fbc98ceff4665738ae9426a72b76947eba533e70e4a5d3cb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 651eda14274678a9eca87769807f423d1129d7a522fb2ad1ca1c66e39818250d18856a1d74a5b4777ba8b85a9281714dfab94507d02203d27284bad43f55d47e
|
|
7
|
+
data.tar.gz: 2297515a85935bfc6f27730f66c4369f979d83400ac9943e89c3ed0ff784051ede30051b7518c9630e9f5c65f81e90bd61a048400e42c10ea935c81213dbcb70
|
data/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Ticktok
|
|
2
|
+
|
|
3
|
+
A simple Ruby gem for tracking execution time of code blocks.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'ticktok'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
$ bundle install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ gem install ticktok
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require 'ticktok'
|
|
29
|
+
|
|
30
|
+
# Track execution time of a code block with a name
|
|
31
|
+
Ticktok.track(:operation_1) do
|
|
32
|
+
# Your code here
|
|
33
|
+
sleep(1)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Track another operation
|
|
37
|
+
Ticktok.track(:operation_2) do
|
|
38
|
+
# Some other code
|
|
39
|
+
sleep(0.5)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Track the first operation again
|
|
43
|
+
Ticktok.track(:operation_1) do
|
|
44
|
+
# More code
|
|
45
|
+
sleep(1.5)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Get all timers with total times
|
|
49
|
+
Ticktok.timers
|
|
50
|
+
# => {:operation_1=>2.5, :operation_2=>0.5}
|
|
51
|
+
|
|
52
|
+
# Get detailed stats for all timers
|
|
53
|
+
Ticktok.detailed_timers
|
|
54
|
+
# => {:operation_1=>{:total=>2.5, :count=>2, :average=>1.25}, :operation_2=>{:total=>0.5, :count=>1, :average=>0.5}}
|
|
55
|
+
|
|
56
|
+
# Reset all timers
|
|
57
|
+
Ticktok.reset
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Contributing
|
|
61
|
+
|
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mumenmusa/ticktok.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
The gem is available as open source under the terms of the MIT License.
|
data/lib/ticktok.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ticktok/version"
|
|
4
|
+
|
|
5
|
+
module Ticktok
|
|
6
|
+
class Timer
|
|
7
|
+
attr_reader :total_time, :count
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@total_time = 0
|
|
11
|
+
@count = 0
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add(elapsed)
|
|
15
|
+
@total_time += elapsed
|
|
16
|
+
@count += 1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def average
|
|
20
|
+
return 0 if @count == 0
|
|
21
|
+
@total_time / @count
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@timers = {}
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
def track(name)
|
|
29
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
30
|
+
result = yield if block_given?
|
|
31
|
+
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
32
|
+
elapsed = end_time - start_time
|
|
33
|
+
|
|
34
|
+
@timers[name] ||= Timer.new
|
|
35
|
+
@timers[name].add(elapsed)
|
|
36
|
+
|
|
37
|
+
result
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def timers
|
|
41
|
+
@timers.transform_values(&:total_time)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def detailed_timers
|
|
45
|
+
result = {}
|
|
46
|
+
@timers.each do |name, timer|
|
|
47
|
+
result[name] = {
|
|
48
|
+
total: timer.total_time,
|
|
49
|
+
count: timer.count,
|
|
50
|
+
average: timer.average
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
result
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def reset
|
|
57
|
+
@timers = {}
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ticktok
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Mumen Musa
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-04-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '13.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '13.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description: Ticktok provides a simple way to measure and track execution time in
|
|
56
|
+
your Ruby code
|
|
57
|
+
email:
|
|
58
|
+
- mumen@musa.ai
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- README.md
|
|
64
|
+
- lib/ticktok.rb
|
|
65
|
+
- lib/ticktok/version.rb
|
|
66
|
+
homepage: https://github.com/mumenmusa/ticktok
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata: {}
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubygems_version: 3.4.19
|
|
86
|
+
signing_key:
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: A gem for tracking time for benchmarks
|
|
89
|
+
test_files: []
|