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