📄 statrecord.h
字号:
/* * statrecord.c -- * * Simple routines for gathering statistics. * */#include <math.h>#ifndef MAXFLOAT#define MAXFLOAT FLT_MAX#endiftypedef struct StatRecord { int64 min, max; float total, squareTotal; int n;} StatRecord;static inline voidStatRecord_Print(StatRecord *r, const char *name){ printf("(* %s: %d samples: %.2f mean, %d min, %d max, %.2f variance *)\n", name, r->n, r->total / r->n, (int) r->min, (int) r->max, r->squareTotal / r->n - r->total / r->n * r->total / r->n);}static inline voidStatRecord_Clear(StatRecord *r) { r->min = ((int64) 1)<<62; r->max = 0; r->total = r->squareTotal = 0.0f; r->n = 0;}static inline voidStatRecord_Record(StatRecord *r, int64 time){ int usec = (int) (CyclesToUsecs(time)); if (usec < r->min) r->min = usec; if (usec > r->max) r->max = usec; r->total += usec; r->squareTotal = r->squareTotal + usec * usec; r->n++;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -