]> gitweb.factorcode.org Git - factor.git/blob - extra/game/loop/benchmark/benchmark.factor
9e1b3fe91584e58fdb312754ae4d299e1f4a9611
[factor.git] / extra / game / loop / benchmark / benchmark.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: accessors alien.c-types classes.struct game.loop
3 game.loop.private kernel sequences specialized-vectors
4 tools.time.struct ;
5 IN: game.loop.benchmark
6
7 STRUCT: game-loop-benchmark
8     { benchmark-data-pair benchmark-data-pair }
9     { tick# ulonglong }
10     { frame# ulonglong } ;
11
12 SPECIALIZED-VECTOR: game-loop-benchmark
13
14 : <game-loop-benchmark> ( benchmark-data-pair tick frame -- obj )
15     \ game-loop-benchmark <struct>
16         swap >>frame#
17         swap >>tick#
18         swap >>benchmark-data-pair ; inline
19
20 : ensure-benchmark-data ( loop -- vector )
21     dup benchmark-data>> [
22         game-loop-benchmark-vector{ } clone
23         >>benchmark-data
24     ] unless
25     benchmark-data>> ; inline
26
27 M: game-loop record-benchmarking ( loop quot: ( loop -- benchmark-data-pair ) -- )
28     [
29         [ [ call( loop -- ) ] with-benchmarking ]
30         [ drop tick#>> ]
31         [ drop frame#>> ]
32         2tri
33         <game-loop-benchmark>
34     ]
35     [ drop ensure-benchmark-data ]
36     2bi push ;
37