module Hitimes

The top level module containing the contents of the hitimes library

use the library with:

require 'hitimes'

Copyright © 2008 Jeremy Hinegardner All rights reserved. See LICENSE and/or COPYING for details.

Constants

MutexedStats

MutexedStats is the start of a threadsafe Stats class. Currently, on MRI Ruby the Stats object is already threadsafe, so there is no need to use MutexedStats.

VERSION

Public Class Methods

clock_description() click to toggle source

The human readable clock description that is used by hitimes

Returns

Returns the clock description as a String

# File lib/hitimes/instant.rb, line 61
def clock_description
  "#{clock_name} #{clock_resolution_description}"
end
clock_name() click to toggle source

The human readable clock name of the CLOCK_ID as a string

Returns

Returns the clock name as a String

# File lib/hitimes/instant.rb, line 37
def clock_name
  case CLOCK_ID
  when Symbol
    CLOCK_ID.to_s
  else
    const = Process.constants.grep(/CLOCK/).find { |c|
      CLOCK_ID == Process.const_get(c)
    }
    "Process::#{const.to_s}"
  end
end
clock_resolution_description() click to toggle source

The human readable clock resolution

Returns

Returns the clock resolution as a string

# File lib/hitimes/instant.rb, line 53
def clock_resolution_description
  "#{CLOCK_RESOLUTION_NANOSECONDS}ns"
end
measure(&block) click to toggle source

::measure { } -> Float

Times the execution of the block, returning the number of seconds it took

# File lib/hitimes.rb, line 22
def self.measure(&block)
  Hitimes::Interval.measure(&block)
end
raw_instant() click to toggle source

Get the raw instant

Examples:

Hitimes.raw_instant

Returns

Returns the raw instant value

# File lib/hitimes/instant.rb, line 29
def raw_instant
  Process.clock_gettime(::Hitimes::CLOCK_ID, :nanosecond)
end

Public

↑ top

Constants

CLOCK_ID

The clock_id to use in Process.clock_gettime

CLOCK_RESOLUTION_NANOSECONDS

The resolution of the clock

CLOCK_RESOLUTION_SECONDS

The smallest fraction of a second hitimes can do

INSTANT_CONVERSION_FACTOR

The factor used to convert the instant values to fractional seconds

The raw instant values are divided by this value to get float seconds

Private Instance Methods

raw_instant() click to toggle source

Get the raw instant

Examples:

Hitimes.raw_instant

Returns

Returns the raw instant value

# File lib/hitimes/instant.rb, line 29
def raw_instant
  Process.clock_gettime(::Hitimes::CLOCK_ID, :nanosecond)
end

Internal

↑ top

Constants

NANOSECONDS_PER_SECOND

The fraction of second of a nanosecond

Private Instance Methods

clock_description() click to toggle source

The human readable clock description that is used by hitimes

Returns

Returns the clock description as a String

# File lib/hitimes/instant.rb, line 61
def clock_description
  "#{clock_name} #{clock_resolution_description}"
end
clock_name() click to toggle source

The human readable clock name of the CLOCK_ID as a string

Returns

Returns the clock name as a String

# File lib/hitimes/instant.rb, line 37
def clock_name
  case CLOCK_ID
  when Symbol
    CLOCK_ID.to_s
  else
    const = Process.constants.grep(/CLOCK/).find { |c|
      CLOCK_ID == Process.const_get(c)
    }
    "Process::#{const.to_s}"
  end
end
clock_resolution_description() click to toggle source

The human readable clock resolution

Returns

Returns the clock resolution as a string

# File lib/hitimes/instant.rb, line 53
def clock_resolution_description
  "#{CLOCK_RESOLUTION_NANOSECONDS}ns"
end