mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	
							parent
							
								
									9328112b9d
								
							
						
					
					
						commit
						3a7ff66abc
					
				
					 2 changed files with 23 additions and 0 deletions
				
			
		|  | @ -527,6 +527,20 @@ module Benchmark | |||
|       [@label, @utime, @stime, @cutime, @cstime, @real] | ||||
|     end | ||||
| 
 | ||||
|     # | ||||
|     # Returns a hash containing the same data as `to_a`. | ||||
|     # | ||||
|     def to_h | ||||
|       { | ||||
|         label:  @label, | ||||
|         utime:  @utime, | ||||
|         stime:  @stime, | ||||
|         cutime: @cutime, | ||||
|         cstime: @cstime, | ||||
|         real:   @real | ||||
|       } | ||||
|     end | ||||
| 
 | ||||
|     protected | ||||
| 
 | ||||
|     # | ||||
|  |  | |||
|  | @ -155,4 +155,13 @@ BENCH | |||
|     realtime = Benchmark.realtime { sleep sleeptime } | ||||
|     assert_operator sleeptime, :<, realtime | ||||
|   end | ||||
| 
 | ||||
|   # Test that `to_h` returns a hash with the expected data. | ||||
|   def test_tms_to_h | ||||
|     tms = Benchmark::Tms.new(1.1, 2.2, 3.3, 4.4, 5.5, 'my label') | ||||
|     expected_hash = { | ||||
|       utime: 1.1, stime: 2.2, cutime: 3.3, cstime: 4.4, real: 5.5, label: 'my label' | ||||
|     } | ||||
|     assert_equal(expected_hash, tms.to_h) | ||||
|   end | ||||
| end | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Keith Bennett
						Keith Bennett