dlvhex
2.5.0
|
00001 /* dlvhex -- Answer-Set Programming with external interfaces. 00002 * Copyright (C) 2005, 2006, 2007 Roman Schindlauer 00003 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Thomas Krennwallner 00004 * Copyright (C) 2009-2015 Peter Schüller 00005 * 00006 * This file is part of dlvhex. 00007 * 00008 * dlvhex is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU Lesser General Public License as 00010 * published by the Free Software Foundation; either version 2.1 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * dlvhex is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with dlvhex; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA. 00022 */ 00023 00031 #ifdef HAVE_CONFIG_H 00032 #include "config.h" 00033 #endif // HAVE_CONFIG_H 00034 00035 #include "dlvhex2/Benchmarking.h" 00036 #include "dlvhex2/Logger.h" 00037 00038 #define BOOST_TEST_MODULE "TestBenchmarking" 00039 #include <boost/test/unit_test.hpp> 00040 00041 #include <iostream> 00042 00043 #include <time.h> 00044 00045 LOG_INIT(Logger::ERROR | Logger::WARNING) 00046 00047 DLVHEX_NAMESPACE_USE 00048 00049 typedef benchmark::ID BID; 00050 00051 void millisleep(unsigned ms) { 00052 struct timespec ts; 00053 ts.tv_sec = 0; 00054 while( ms > 1000 ) { 00055 ts.tv_sec ++; 00056 ms -= 1000; 00057 } 00058 ts.tv_nsec = ms*1000L*1000L; 00059 nanosleep(&ts, NULL); 00060 } 00061 00062 BOOST_AUTO_TEST_CASE(nestingAware) 00063 { 00064 // create controller singleton 00065 typedef benchmark::nestingAware::NestingAwareController Controller; 00066 Controller& ctrl = Controller::Instance(); 00067 00068 BID id1 = ctrl.getInstrumentationID("1"); 00069 BID id2 = ctrl.getInstrumentationID("2"); 00070 00071 ctrl.start(id2); 00072 millisleep(100); // assume this is not exact 00073 { 00074 ctrl.start(id1); 00075 millisleep(100); // assume this is not exact 00076 // start again! 00077 ctrl.start(id1); 00078 millisleep(100); // assume this is not exact 00079 ctrl.stop(id1); 00080 millisleep(100); // assume this is not exact 00081 ctrl.stop(id1); 00082 } 00083 millisleep(100); // assume this is not exact 00084 ctrl.stop(id2); 00085 00086 std::stringstream ss; 00087 ss << ctrl.duration("1", 1) << " " << ctrl.duration("2", 1); 00088 float f1, f2; 00089 ss >> f1 >> f2; 00090 LOG(WARNING, "got durations 1:" << f1 << " 2:" << f2); 00091 BOOST_CHECK(f1 > 0.095*3); 00092 BOOST_CHECK(f1 < 0.105*3); 00093 BOOST_CHECK(f2 > 0.095*2); 00094 BOOST_CHECK(f2 < 0.105*2); 00095 } 00096 00097 // Local Variables: 00098 // mode: C++ 00099 // End: