Class: Aims::Timings
- Inherits:
-
Object
- Object
- Aims::Timings
- Defined in:
- lib/aims/output.rb
Overview
A class for encapsulating computational timing information
Instance Method Summary collapse
-
#add!(timings) ⇒ Object
Add another timings object to this one.
-
#add_cpu_time(desc, time) ⇒ Object
Add cpu timing data for the given description.
-
#add_wall_time(desc, time) ⇒ Object
Add wall timing data for the given description.
-
#cpu_time(desc) ⇒ Object
Get cpu timing data for the given description.
-
#descriptions ⇒ Object
Get all the descriptions for this timing object.
-
#each ⇒ Object
Enumerate over an array of hashes that looks like: [=> “Something”, :cpu_time => 10.0, :wall_time => 10.1, …].
-
#initialize ⇒ Timings
constructor
Initialize a new timing.
-
#total_cpu_time ⇒ Object
Get the total cpu time.
-
#total_wall_time ⇒ Object
Get the total wall time.
-
#wall_time(desc) ⇒ Object
Get wall timing data for the given description.
Constructor Details
#initialize ⇒ Timings
Initialize a new timing
84 85 86 |
# File 'lib/aims/output.rb', line 84 def initialize @timing_hash = {} end |
Instance Method Details
#add!(timings) ⇒ Object
Add another timings object to this one
98 99 100 101 102 103 |
# File 'lib/aims/output.rb', line 98 def add!(timings) timings.descriptions.each{|d| add_cpu_time(d, timings.cpu_time(d)) add_wall_time(d, timings.wall_time(d)) } end |
#add_cpu_time(desc, time) ⇒ Object
Add cpu timing data for the given description
111 112 113 114 |
# File 'lib/aims/output.rb', line 111 def add_cpu_time(desc, time) @timing_hash[desc] = {:cpu_time => 0, :wall_time => 0} unless @timing_hash[desc] @timing_hash[desc][:cpu_time] += time end |
#add_wall_time(desc, time) ⇒ Object
Add wall timing data for the given description
117 118 119 120 |
# File 'lib/aims/output.rb', line 117 def add_wall_time(desc, time) @timing_hash[desc] = {:cpu_time => 0, :wall_time => 0} unless @timing_hash[desc] @timing_hash[desc][:wall_time] += time end |
#cpu_time(desc) ⇒ Object
Get cpu timing data for the given description
139 140 141 142 143 144 145 |
# File 'lib/aims/output.rb', line 139 def cpu_time(desc) if @timing_hash[desc] @timing_hash[desc][:cpu_time] || 0 else 0 end end |
#descriptions ⇒ Object
Get all the descriptions for this timing object
106 107 108 |
# File 'lib/aims/output.rb', line 106 def descriptions @timing_hash.keys end |
#each ⇒ Object
Enumerate over an array of hashes that looks like:
- => “Something”, :cpu_time => 10.0, :wall_time => 10.1, …
90 91 92 93 94 95 |
# File 'lib/aims/output.rb', line 90 def each @timing_hash.each_pair{|desc,timings| h = {:description => desc, :cpu_time => timings[:cpu_time], :wall_time => timings[:wall_time]} yield h } end |
#total_cpu_time ⇒ Object
Get the total cpu time
148 149 150 151 152 |
# File 'lib/aims/output.rb', line 148 def total_cpu_time @timing_hash.inject(0) {|total, a| total += a[1][:cpu_time] } end |
#total_wall_time ⇒ Object
Get the total wall time
132 133 134 135 136 |
# File 'lib/aims/output.rb', line 132 def total_wall_time @timing_hash.inject(0) {|total, a| total += a[1][:wall_time] } end |
#wall_time(desc) ⇒ Object
Get wall timing data for the given description
123 124 125 126 127 128 129 |
# File 'lib/aims/output.rb', line 123 def wall_time(desc) if @timing_hash[desc] @timing_hash[desc][:wall_time] || 0 else 0 end end |