Unit Tests - t.benchmark.t

- Added benchmark to measure time taken to parse 1,000,000 T records.
This commit is contained in:
Paul Beckingham 2009-03-08 17:59:27 -04:00
parent 3088e1ebe1
commit 4fa4c5f532
5 changed files with 80 additions and 11 deletions

View file

@ -14,12 +14,10 @@ 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"
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)
fi

View file

@ -468,7 +468,7 @@ void T::parse (const std::string& line)
break;
default:
throw std::string ();
throw std::string ("Unrecognized task file format.");
break;
}
}

View file

@ -1,7 +1,6 @@
t.t
t.benchmark.t
tdb.t
date.t
duration.t
pending.data
completed.data

View file

@ -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

View file

@ -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 <sys/time.h>
#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;
}
////////////////////////////////////////////////////////////////////////////////