class Time
Represents a timing sample for benchmarking, including user, system, and real time.
Definitions
def self.measure
Measures the execution time of a block, returning a new class Sus::Fixtures::Benchmark::Time
object with user, system, and real time.
Signature
-
returns
Time
The measured timing sample.
Implementation
def self.measure
t0, r0 = Process.times, Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
t1, r1 = Process.times, Process.clock_gettime(Process::CLOCK_MONOTONIC)
self.new(
t1.utime - t0.utime,
t1.stime - t0.stime,
r1 - r0,
)
end
def initialize(user = 0.0, system = 0.0, real = 0.0)
Initializes a new class Sus::Fixtures::Benchmark::Time
object with user, system, and real time values.
Signature
-
parameter
user
Float
The user CPU time in seconds.
-
parameter
system
Float
The system CPU time in seconds.
-
parameter
real
Float
The real (wall clock) time in seconds.
Implementation
def initialize(user = 0.0, system = 0.0, real = 0.0)
@user = user
@system = system
@real = real
end
attr :user
The user CPU time in seconds.
Signature
-
returns
Float
attr :system
The system CPU time in seconds.
Signature
-
returns
Float
attr :real
The real (wall clock) time in seconds.
Signature
-
returns
Float
def to_s
Returns a string representation of the real time in seconds.
Signature
-
returns
String
Implementation
def to_s
"#{self.real}s"
end
def inspect
Returns a detailed string representation of the timing sample.
Signature
-
returns
String
Implementation
def inspect
"#<#{self.class} user=#{self.user}s system=#{self.system}s real=#{self.real}s>"
end