From 4fa4c5f532313ea0d7b853fb8e09b3741b6b3113 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 8 Mar 2009 17:59:27 -0400 Subject: [PATCH] Unit Tests - t.benchmark.t - Added benchmark to measure time taken to parse 1,000,000 T records. --- configure.ac | 12 +++---- src/T.cpp | 2 +- src/tests/.gitignore | 3 +- src/tests/Makefile | 5 ++- src/tests/t.benchmark.t.cpp | 69 +++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 src/tests/t.benchmark.t.cpp diff --git a/configure.ac b/configure.ac index d6e95db0f..4ae1d6760 100644 --- a/configure.ac +++ b/configure.ac @@ -14,14 +14,12 @@ debug_default="yes" AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging [default=$debug_default]],, enable_debug=$debug_default) # Yes, shell scripts can be used -if test "x$enable_debug" = "xyes"; then -CFLAGS="$CFLAGS -Wall -pedantic -ggdb3 -DDEBUG" -CXXFLAGS="$CFLAGS -Wall -pedantic -ggdb3 -DDEBUG" -AC_MSG_RESULT(yes) +if test "$enable_debug" = "yes"; then + CXXFLAGS="$CFLAGS -Wall -pedantic -ggdb3 -DDEBUG" + AC_MSG_RESULT(yes) else -CFLAGS="$CFLAGS -O3" -CXXFLAGS="$CFLAGS -O3" -AC_MSG_RESULT(no) + CXXFLAGS="$CFLAGS -O3" + AC_MSG_RESULT(no) fi # Check for OS. diff --git a/src/T.cpp b/src/T.cpp index a21b31638..61acd52f4 100644 --- a/src/T.cpp +++ b/src/T.cpp @@ -468,7 +468,7 @@ void T::parse (const std::string& line) break; default: - throw std::string (); + throw std::string ("Unrecognized task file format."); break; } } diff --git a/src/tests/.gitignore b/src/tests/.gitignore index 1445bb223..94ab5cd82 100644 --- a/src/tests/.gitignore +++ b/src/tests/.gitignore @@ -1,7 +1,6 @@ t.t +t.benchmark.t tdb.t date.t duration.t -pending.data -completed.data diff --git a/src/tests/Makefile b/src/tests/Makefile index c6c3ac3d8..b98b58bd4 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -1,4 +1,4 @@ -PROJECT = t.t tdb.t date.t duration.t +PROJECT = t.t tdb.t date.t duration.t t.benchmark.t CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti LFLAGS = -L/usr/local/lib OBJECTS = ../TDB.o ../T.o ../parse.o ../text.o ../Date.o ../util.o ../Config.o @@ -29,3 +29,6 @@ date.t: date.t.o $(OBJECTS) test.o duration.t: duration.t.o $(OBJECTS) test.o g++ duration.t.o $(OBJECTS) test.o $(LFLAGS) -o duration.t +t.benchmark.t: t.benchmark.t.o $(OBJECTS) test.o + g++ t.benchmark.t.o $(OBJECTS) test.o $(LFLAGS) -o t.benchmark.t + diff --git a/src/tests/t.benchmark.t.cpp b/src/tests/t.benchmark.t.cpp new file mode 100644 index 000000000..9adf4d578 --- /dev/null +++ b/src/tests/t.benchmark.t.cpp @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////////////// +// task - a command line task list manager. +// +// Copyright 2006 - 2009, Paul Beckingham. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program 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 General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// +#include +#include "../T.h" +#include "../task.h" +#include "test.h" + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest test (1); + + std::string sample = "d346065c-7ef6-49af-ae77-19c1825807f5 " + "- " + "[bug performance solaris linux osx] " + "[due:1236142800 entry:1236177552 priority:H project:task-1.5.0 start:1236231761] " + "Profile task and identify performance bottlenecks"; + + // Start clock + test.diag ("start"); + struct timeval start; + gettimeofday (&start, NULL); + + for (int i = 0; i < 1000000; i++) + { + T t (sample); + } + + // End clock + struct timeval end; + gettimeofday (&end, NULL); + test.diag ("end"); + + int diff = ((end.tv_sec * 1000000) + end.tv_usec) - + ((start.tv_sec * 1000000) + start.tv_usec); + + char s[16]; + sprintf (s, "%d.%06d", diff/1000000, diff%1000000); + test.pass (std::string ("1,000,000 T::parse calls in ") + s + "s"); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +