File: hitimes.rb

package info (click to toggle)
ruby-hitimes 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 388 kB
  • sloc: ruby: 1,196; ansic: 418; java: 265; makefile: 15
file content (66 lines) | stat: -rw-r--r-- 1,550 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#--
# Copyright (c) 2008 Jeremy Hinegardner
# All rights reserved.  See LICENSE and/or COPYING for details.
#++

#
# The top level module containing the contents of the hitimes library
#
# use the library with:
#
#   require 'hitimes'
#
module Hitimes
  #
  # Base class of all errors in Hitimes
  #
  class Error < ::StandardError; end

  # Hitimes.measure { } -> Float
  #
  # Times the execution of the block, returning the number of seconds it took
  def self.measure(&block)
    Hitimes::Interval.measure(&block)
  end
end
require 'hitimes/paths'
require 'hitimes/version'

# Load the binary extension, try loading one for the specific version of ruby
# and if that fails, then fall back to one in the top of the library.
# this is the method recommended by rake-compiler

attempts = [
  "hitimes/#{RUBY_VERSION.sub(/\.\d+$/,'')}/hitimes",
  "hitimes/hitimes"
]
loaded = false

path_exceptions = []
attempts.each do |path|
  begin
    require path
    loaded = true
    break
  rescue LoadError => load_error
    full_path = File.expand_path(path)
    path_exceptions << [ full_path, load_error.message ]
  end
end

if !loaded then
  msg = ["Unable to find binary extension, was hitimes installed correctly? The following paths were tried."]
  path_exceptions.each do |path, message|
    msg << "#{path} : #{message}"
  end
  raise LoadError, msg.join("\n")
end

require 'hitimes/stats'
require 'hitimes/mutexed_stats'

require 'hitimes/metric'
require 'hitimes/value_metric'
require 'hitimes/timed_metric'
require 'hitimes/timed_value_metric'