SDSL: Succinct Data Structure Library
A C++ template library for succinct data structures
|
00001 /* sdsl - succinct data structures library 00002 Copyright (C) 2008 Simon Gog 00003 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program. If not, see http://www.gnu.org/licenses/ . 00016 */ 00021 #ifndef INCLUDE_SDSL_TESTUTILS 00022 #define INCLUDE_SDSL_TESTUTILS 00023 00024 #include "util.hpp" 00025 #include "uintx_t.hpp" 00026 #include <sys/time.h> // for struct timeval 00027 #include <sys/resource.h> // for struct rusage 00028 #include <iomanip> 00029 #include <iostream> 00030 #include <string> 00031 00032 namespace sdsl 00033 { 00034 00036 00040 class stop_watch 00041 { 00042 private: 00043 rusage m_ruse1, m_ruse2; 00044 timeval m_timeOfDay1, m_timeOfDay2; 00045 static timeval m_first_t; 00046 static rusage m_first_r; 00047 public: 00048 00049 stop_watch() : m_ruse1(), m_ruse2(), m_timeOfDay1(), m_timeOfDay2() { 00050 timeval t; 00051 t.tv_sec = 0; t.tv_usec = 0; 00052 m_ruse1.ru_utime = t; m_ruse1.ru_stime = t; // init m_ruse1 00053 m_ruse2.ru_utime = t; m_ruse2.ru_stime = t; // init m_ruse2 00054 m_timeOfDay1 = t; m_timeOfDay2 = t; 00055 if (m_first_t.tv_sec == 0) { 00056 gettimeofday(&m_first_t, 0); 00057 } 00058 if (m_first_r.ru_utime.tv_sec == 0 and m_first_r.ru_utime.tv_usec ==0) { 00059 getrusage(RUSAGE_SELF, &m_first_r); 00060 } 00061 } 00063 00065 void start(); 00066 00068 00070 void stop(); 00071 00073 00075 double get_user_time(); 00076 00078 00080 double get_sys_time(); 00081 00083 00085 double get_real_time(); 00086 00088 00090 uint64_t get_abs_user_time(); 00091 00093 00095 uint64_t get_abs_sys_time(); 00096 00098 00100 uint64_t get_abs_real_time(); 00101 00102 uint64_t get_abs_page_faults(); 00103 }; 00104 00106 inline void write_R_output(std::string data_structure, std::string action, 00107 std::string state="begin", uint64_t times=1, uint64_t check=0) 00108 { 00109 if (util::verbose) { 00110 stop_watch _sw; 00111 _sw.stop(); 00112 std::cout << data_structure << "\t" << action << "\t" << state << "\t" 00113 << std::setw(9)<< times << "\t" << std::setw(9) << check << "\t" 00114 << std::setw(9) << _sw.get_abs_real_time() << "\t " 00115 << std::setw(9) << _sw.get_abs_user_time() << "\t" 00116 << std::setw(9) << _sw.get_abs_sys_time() << std::endl; 00117 } 00118 } 00119 00121 class clock 00122 { 00123 public: 00124 static std::string get_time_string(); 00125 }; 00126 00128 off_t get_file_size(const char* file_name); 00129 00130 00132 class file 00133 { 00134 public: 00136 00147 static uint64_t read_text(const char* file_name, char*& c, bool trunc=0, uint64_t lim=0); 00148 00149 static void write_text(const char* file_name, const char* c, uint64_t len); 00150 }; 00151 00152 } // end of namespace sdsl 00153 00154 #endif