Module: TWPipeline::Bench
- Defined in:
- lib/twpipeline/bench.rb,
sig/twpipeline.rbs
Defined Under Namespace
Classes: Sample
Class Method Summary collapse
- .cpu_seconds ⇒ Object
- .measure(label, **facts) ⇒ Object
- .path ⇒ Object
- .peak_rss ⇒ Object
- .record(sample) ⇒ Object
Instance Method Summary collapse
- #self?.cpu_seconds ⇒ ::Float
- #self?.measure { ... } ⇒ Sample
- #self?.path ⇒ Pathname
- #self?.peak_rss ⇒ ::Integer
- #self?.record ⇒ Sample
Class Method Details
.cpu_seconds ⇒ Object
42 43 44 45 |
# File 'lib/twpipeline/bench.rb', line 42 def cpu_seconds times = Process.times times.utime + times.stime + times.cutime + times.cstime end |
.measure(label, **facts) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/twpipeline/bench.rb', line 27 def measure(label, **facts) started = Process.clock_gettime(Process::CLOCK_MONOTONIC) cpu_before = cpu_seconds result = yield sample = Sample.new( label: label, seconds: Process.clock_gettime(Process::CLOCK_MONOTONIC) - started, cpu_seconds: cpu_seconds - cpu_before, peak_rss_bytes: peak_rss, facts: facts.merge(result.is_a?(Hash) ? result : {}) ) record(sample) sample end |
.path ⇒ Object
25 |
# File 'lib/twpipeline/bench.rb', line 25 def path = Pathname(ENV.fetch("TWP_BENCHMARKS", TWPipeline.work.join("benchmarks.jsonl").to_s)) |
.record(sample) ⇒ Object
49 50 51 52 53 |
# File 'lib/twpipeline/bench.rb', line 49 def record(sample) path.dirname.mkpath path.open("a") { |io| io.puts(JSON.generate({at: Time.now.utc.iso8601}.merge(sample.to_h))) } sample end |
Instance Method Details
#self?.cpu_seconds ⇒ ::Float
78 |
# File 'sig/twpipeline.rbs', line 78
def self?.cpu_seconds: () -> ::Float
|
#self?.measure { ... } ⇒ Sample
77 |
# File 'sig/twpipeline.rbs', line 77
def self?.measure: (::String label, **untyped facts) { () -> untyped } -> Sample
|
#self?.path ⇒ Pathname
76 |
# File 'sig/twpipeline.rbs', line 76
def self?.path: () -> Pathname
|
#self?.peak_rss ⇒ ::Integer
79 |
# File 'sig/twpipeline.rbs', line 79
def self?.peak_rss: () -> ::Integer
|