Skip to content
class method · added in Ruby 3.1

GC.total_time

() -> ::Integer
GC.total_time → integer

Returns the GC total time in nanoseconds:

Example
GC.total_time # => 156250

Note that total time accumulates only when total time measurement is enabled (that is, when GC.measure_total_time is true):

Example
GC.measure_total_time # => true
GC.total_time # => 625000
GC.start
GC.total_time # => 937500
GC.start
GC.total_time # => 1093750

GC.measure_total_time = false
GC.total_time # => 1250000
GC.start
GC.total_time # => 1250000
GC.start
GC.total_time # => 1250000

GC.measure_total_time = true
GC.total_time # => 1250000
GC.start
GC.total_time # => 1406250

Ruby version changes

  1. 3.1
See also .stress= #garbage_collect .stress also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1