medfall

A super great game engine
Log | Files | Refs

stats.h (637B)


      1 #pragma once
      2 
      3 #include "intrinsics.h"
      4 #include "ggformat.h"
      5 #include "rng/pcg.h"
      6 
      7 const u32 STATS_NUM_QUART_SAMPLES = 1024;
      8 
      9 // TODO: make this thread-safe
     10 struct Stats {
     11 	double sum;
     12 	double sum_of_squares;
     13 	double min;
     14 	double max;
     15 	u64 num_records;
     16 
     17 	PCG rng;
     18 
     19 	// mutable because we sort samples to pull out percentiles in format
     20 	mutable double samples[ STATS_NUM_QUART_SAMPLES ];
     21 };
     22 
     23 void stats_init( Stats * stats );
     24 double stats_mean( const Stats * stats );
     25 double stats_stddev( const Stats * stats );
     26 void stats_record( Stats * stats, double x );
     27 
     28 void format( FormatBuffer * fb, const Stats & stats, const FormatOpts & opts );