factor/extra/game/loop/benchmark/benchmark.factor

38 lines
1.0 KiB
Factor
Raw Permalink Normal View History

! Copyright (C) 2009 Joe Groff.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types classes.struct game.loop
game.loop.private kernel sequences specialized-vectors
tools.time.struct ;
IN: game.loop.benchmark
STRUCT: game-loop-benchmark
{ benchmark-data-pair benchmark-data-pair }
{ tick# ulonglong }
{ frame# ulonglong } ;
SPECIALIZED-VECTOR: game-loop-benchmark
: <game-loop-benchmark> ( benchmark-data-pair tick frame -- obj )
\ game-loop-benchmark <struct>
swap >>frame#
swap >>tick#
swap >>benchmark-data-pair ; inline
: ensure-benchmark-data ( loop -- vector )
dup benchmark-data>> [
game-loop-benchmark-vector{ } clone
>>benchmark-data
] unless
benchmark-data>> ; inline
M: game-loop record-benchmarking ( loop quot: ( loop -- benchmark-data-pair ) -- )
[
[ [ call( loop -- ) ] with-benchmarking ]
[ drop tick#>> ]
[ drop frame#>> ]
2tri
<game-loop-benchmark>
]
[ drop ensure-benchmark-data ]
2bi push ;