Rewrite of collect-benchmarks in ave-time vocab
							parent
							
								
									9d06315809
								
							
						
					
					
						commit
						e923ec16d3
					
				|  | @ -1,20 +1,21 @@ | ||||||
| ! Copyright (c) 2007 Aaron Schaefer. | ! Copyright (c) 2007 Aaron Schaefer. | ||||||
| ! See http://factorcode.org/license.txt for BSD license. | ! See http://factorcode.org/license.txt for BSD license. | ||||||
| USING: continuations io kernel math math.functions math.parser math.statistics | USING: continuations fry io kernel make math math.functions math.parser | ||||||
|     namespaces make tools.time ; |     math.statistics memory tools.time ; | ||||||
| IN: project-euler.ave-time | IN: project-euler.ave-time | ||||||
| 
 | 
 | ||||||
| : collect-benchmarks ( quot n -- seq ) | : collect-benchmarks ( quot n -- seq ) | ||||||
|   [ |     [ | ||||||
|     >r >r datastack r> [ benchmark , ] curry tuck |         [ datastack ] | ||||||
|     [ with-datastack drop ] 2curry r> swap times call |         [ '[ _ gc benchmark , ] tuck '[ _ _ with-datastack drop ] ] | ||||||
|   ] { } make ; |         [ 1- ] tri* swap times call | ||||||
|  |     ] { } make ; | ||||||
| 
 | 
 | ||||||
| : nth-place ( x n -- y ) | : nth-place ( x n -- y ) | ||||||
|     10 swap ^ [ * round ] keep / ; |     10 swap ^ [ * round ] keep / ; | ||||||
| 
 | 
 | ||||||
| : ave-time ( quot n -- ) | : ave-time ( quot n -- ) | ||||||
|     [ collect-benchmarks ] keep |     [ collect-benchmarks ] keep swap | ||||||
|     swap [ std 2 nth-place ] [ mean round ] bi [ |     [ std 2 nth-place ] [ mean round ] bi [ | ||||||
|         # " ms ave run time - " % # " SD (" % # " trials)" % |         # " ms ave run time - " % # " SD (" % # " trials)" % | ||||||
|     ] "" make print flush ; inline |     ] "" make print flush ; inline | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue