susumu.yata
null+****@clear*****
Fri Mar 1 13:50:24 JST 2013
susumu.yata 2013-03-01 13:50:24 +0900 (Fri, 01 Mar 2013) New Revision: 23e31ed74fe7ba6ded2561ab8b36a8efa2032ee7 https://github.com/groonga/grnxx/commit/23e31ed74fe7ba6ded2561ab8b36a8efa2032ee7 Log: Add a test for grnxx::InternalClock. Added files: test/test_internal_clock.cpp Modified files: .gitignore test/Makefile.am Modified: .gitignore (+1 -0) =================================================================== --- .gitignore 2013-03-01 13:50:09 +0900 (66dbbd7) +++ .gitignore 2013-03-01 13:50:24 +0900 (55613a9) @@ -37,6 +37,7 @@ test/test_error test/test_exception test/test_features test/test_grnxx +test/test_internal_clock test/test_intrinsic test/test_io_alpha_pool test/test_io_file Modified: test/Makefile.am (+4 -0) =================================================================== --- test/Makefile.am 2013-03-01 13:50:09 +0900 (72c1ec1) +++ test/Makefile.am 2013-03-01 13:50:24 +0900 (cba1cbf) @@ -11,6 +11,7 @@ TESTS = \ test_exception \ test_features \ test_grnxx \ + test_internal_clock \ test_intrinsic \ test_io_file \ test_io_file_info \ @@ -65,6 +66,9 @@ test_features_LDADD = ../lib/libgrnxx.la test_grnxx_SOURCES = test_grnxx.cpp test_grnxx_LDADD = ../lib/libgrnxx.la +test_internal_clock_SOURCES = test_internal_clock.cpp +test_internal_clock_LDADD = ../lib/libgrnxx.la + test_intrinsic_SOURCES = test_intrinsic.cpp test_intrinsic_LDADD = ../lib/libgrnxx.la Added: test/test_internal_clock.cpp (+67 -0) 100644 =================================================================== --- /dev/null +++ test/test_internal_clock.cpp 2013-03-01 13:50:24 +0900 (9460960) @@ -0,0 +1,67 @@ +/* + Copyright (C) 2012-2013 Brazil, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include <unistd.h> + +#include <cassert> + +#include "logger.hpp" +#include "internal_clock.hpp" +#include "stopwatch.hpp" +#include "thread.hpp" + +int main() { + grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL | + grnxx::LOGGER_ENABLE_COUT); + grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER); + + grnxx::Time time = grnxx::InternalClock::now(); + GRNXX_NOTICE() << "grnxx::InternalClock::now(): " << time; + GRNXX_NOTICE() << "grnxx::InternalClock::now().local_time(): " + << time.local_time(); + + time = grnxx::InternalClock::now(); + GRNXX_NOTICE() << "grnxx::InternalClock::now(): " << time; + GRNXX_NOTICE() << "grnxx::InternalClock::now().local_time(): " + << time.local_time(); + + grnxx::Thread::sleep(grnxx::Duration::milliseconds(500)); + + time = grnxx::InternalClock::now(); + GRNXX_NOTICE() << "grnxx::InternalClock::now(): " << time; + GRNXX_NOTICE() << "grnxx::InternalClock::now().local_time(): " + << time.local_time(); + + grnxx::Thread::sleep(grnxx::Duration::milliseconds(500)); + + time = grnxx::InternalClock::now(); + GRNXX_NOTICE() << "grnxx::InternalClock::now(): " << time; + GRNXX_NOTICE() << "grnxx::InternalClock::now().local_time(): " + << time.local_time(); + + enum { LOOP_COUNT = 1 << 20 }; + + grnxx::Stopwatch stopwatch(true); + for (int i = 0; i < LOOP_COUNT; ++i) { + grnxx::InternalClock::now(); + } + grnxx::Duration elapsed = stopwatch.elapsed(); + GRNXX_NOTICE() << "grnxx::InternalClock::now: average elapsed [ns] = " + << (1000.0 * elapsed.count() / LOOP_COUNT); + + return 0; +} -------------- next part -------------- HTML����������������������������... Download