📄 time.h
字号:
#ifndef TIME_LIB#define TIME_LIB true// time.h Class to give spuedo time of prog execution// W.Langdon@cs.ucl.ac.uk $Revision: 1.9 $ 20 April 1995//requires FASTEVAL and TIMINGS//Modifications (reverse order)://WBL 2 Sep 1995 Support VAR_TIMINGS with add_time//WBL 6 May 1995 add debug info and error handling for when add overflows// Fix overflow by allowing max_times to be much bigger#include <assert.h>extern evalnode* fast_tree_starts [NUM_TREES]; // start of each treeclass run_time { public: typedef int timetyp; private: timetyp time_;// = 0; enum {max_times = 167}; //ie MaxExpr/3 timetyp tree_base_times[NUM_TREES]; class subtree_time { public: evalnode* ip;// = NULL; timetyp ttime;// = 0; subtree_time(): ip(NULL), ttime(0) {}; }; int num_times;// = 0; subtree_time times[max_times+2]; //plus buffer area for errors timetyp subtree (); void sort (const int lower_bound); //upper is num_times - 1 void add (evalnode* ip, timetyp t) { if(num_times>=max_times){ cout<<"run_time::add num_times="<<num_times <<" ip="<<ip<<" t="<<t<<flush; cout<<"fast_tree_starts="; for(int i=0;i<NUM_TREES;i++) cout<<fast_tree_starts[i]<<" "; cout<<endl; cout<<*this<<endl; num_times=max_times+1;//error indication }//end debug output else {// assert(num_times<max_times); times[num_times].ip = ip; times[num_times].ttime = t; num_times++; } } evalnode* ip;// = NULL; public: run_time(); //SetupEval MUST BE CALLED FIRST void add_time(timetyp delta) {time_ += delta;}; void base_time(int tree) {time_ += tree_base_times[tree];}; void opt_time(evalnode* ip) { int bot = 0; //binary chop search, ip will be inorder int top = num_times - 1; do { int i = (top+bot)/2; if(ip == times[i].ip) { time_ += times[i].ttime; goto found; } else if(ip < times[i].ip) top = i - 1; else bot = i + 1; } while(top>=bot); time_ += 999; //error should have been reported before now cout<<"run_time::opt_time fail to find "<<ip <<" num_times="<<num_times<<" "<<flush; cout<<*this<<endl; assert(0==1); //oppsfound:; }; timetyp timmer() { return time_; }; void clear() { time_ = 0; }; friend ostream& operator<<(ostream&,run_time&); inline BOOL too_many_times() const {return (num_times>max_times);};//ie error};//end class run_timeextern run_time* ThisTimmer;#endif //TIME_LIB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -