Permalink
Browse files

Adding speedtest-tune, an adapted speedtest previously used to measur…

…e binary search threshold.
  • Loading branch information...
1 parent 62382d1 commit 1be7adbd338cb257863b1b983acdcd38f2454271 @bingmann committed Mar 16, 2013
Showing with 244 additions and 4 deletions.
  1. +3 −1 speedtest/Makefile.am
  2. +12 −3 speedtest/Makefile.in
  3. +229 −0 speedtest/speedtest-tune.cc
@@ -3,12 +3,14 @@
if BUILD_SPEEDTEST
-noinst_PROGRAMS = speedtest
+noinst_PROGRAMS = speedtest speedtest-tune
endif
speedtest_SOURCES = speedtest.cc
+speedtest_tune_SOURCES = speedtest-tune.cc
+
AM_CXXFLAGS = -W -Wall -Wold-style-cast -DNDEBUG -I$(top_srcdir)/include
EXTRA_DIST = \
View
@@ -54,7 +54,8 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
-@BUILD_SPEEDTEST_TRUE@noinst_PROGRAMS = speedtest$(EXEEXT)
+@BUILD_SPEEDTEST_TRUE@noinst_PROGRAMS = speedtest$(EXEEXT) \
+@BUILD_SPEEDTEST_TRUE@ speedtest-tune$(EXEEXT)
subdir = speedtest
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -68,6 +69,9 @@ PROGRAMS = $(noinst_PROGRAMS)
am_speedtest_OBJECTS = speedtest.$(OBJEXT)
speedtest_OBJECTS = $(am_speedtest_OBJECTS)
speedtest_LDADD = $(LDADD)
+am_speedtest_tune_OBJECTS = speedtest-tune.$(OBJEXT)
+speedtest_tune_OBJECTS = $(am_speedtest_tune_OBJECTS)
+speedtest_tune_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp
am__depfiles_maybe = depfiles
@@ -77,8 +81,8 @@ CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
-o $@
-SOURCES = $(speedtest_SOURCES)
-DIST_SOURCES = $(speedtest_SOURCES)
+SOURCES = $(speedtest_SOURCES) $(speedtest_tune_SOURCES)
+DIST_SOURCES = $(speedtest_SOURCES) $(speedtest_tune_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@@ -201,6 +205,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
speedtest_SOURCES = speedtest.cc
+speedtest_tune_SOURCES = speedtest-tune.cc
AM_CXXFLAGS = -W -Wall -Wold-style-cast -DNDEBUG -I$(top_srcdir)/include
EXTRA_DIST = \
speedtest.gnuplot transpose.awk \
@@ -253,13 +258,17 @@ clean-noinstPROGRAMS:
speedtest$(EXEEXT): $(speedtest_OBJECTS) $(speedtest_DEPENDENCIES) $(EXTRA_speedtest_DEPENDENCIES)
@rm -f speedtest$(EXEEXT)
$(CXXLINK) $(speedtest_OBJECTS) $(speedtest_LDADD) $(LIBS)
+speedtest-tune$(EXEEXT): $(speedtest_tune_OBJECTS) $(speedtest_tune_DEPENDENCIES) $(EXTRA_speedtest_tune_DEPENDENCIES)
+ @rm -f speedtest-tune$(EXEEXT)
+ $(CXXLINK) $(speedtest_tune_OBJECTS) $(speedtest_tune_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/speedtest-tune.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/speedtest.Po@am__quote@
.cc.o:
@@ -0,0 +1,229 @@
+/*
+ * STX B+ Tree Template Classes v0.8.6
+ * Copyright (C) 2008-2013 Timo Bingmann
+ *
+ * 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 <string>
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+
+#include <stx/btree_multiset.h>
+
+#include <assert.h>
+
+// *** Settings
+
+/// maximum number of items to insert
+const unsigned int insertnum = 1024000 * 32;
+
+const int randseed = 34234235;
+
+/// b+ tree binsearch_threshold range to test
+const int min_nodeslots = 564;
+const int max_nodeslots = 564;
+
+/// Time is measured using gettimeofday()
+inline double timestamp()
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec + tv.tv_usec * 0.000001;
+}
+
+/// Traits used for the speed tests, BTREE_DEBUG is not defined.
+template <typename KeyType, int _bs_slots>
+struct btree_traits_speed : public stx::btree_default_set_traits<KeyType>
+{
+ static const int binsearch_threshold = _bs_slots;
+};
+
+/// Test the B+ tree with a specific leaf/inner slots (only insert)
+template <int Slots>
+struct Test_BtreeSet_Insert
+{
+ typedef stx::btree_multiset<unsigned int, std::less<unsigned int>,
+ btree_traits_speed<unsigned int, Slots> > btree_type;
+
+ Test_BtreeSet_Insert(unsigned int) {}
+
+ void run(unsigned int insertnum)
+ {
+ btree_type bt;
+
+ srand(randseed);
+ for(unsigned int i = 0; i < insertnum; i++)
+ bt.insert( rand() );
+
+ assert( bt.size() == insertnum );
+ }
+};
+
+/// Test the B+ tree with a specific leaf/inner slots (insert, find and delete)
+template <int Slots>
+struct Test_BtreeSet_InsertFindDelete
+{
+ typedef stx::btree_multiset<unsigned int, std::less<unsigned int>,
+ struct btree_traits_speed<unsigned int, Slots> > btree_type;
+
+ Test_BtreeSet_InsertFindDelete(unsigned int) {}
+
+ void run(unsigned int insertnum)
+ {
+ btree_type bt;
+
+ srand(randseed);
+ for(unsigned int i = 0; i < insertnum; i++)
+ bt.insert(rand());
+
+ assert( bt.size() == insertnum );
+
+ srand(randseed);
+ for(unsigned int i = 0; i < insertnum; i++)
+ bt.exists(rand());
+
+ srand(randseed);
+ for(unsigned int i = 0; i < insertnum; i++)
+ bt.erase_one(rand());
+
+ assert(bt.empty());
+ }
+};
+
+/// Test the B+ tree with a specific leaf/inner slots (find only)
+template <int Slots>
+struct Test_BtreeSet_Find
+{
+ typedef stx::btree_multiset<unsigned int, std::less<unsigned int>,
+ struct btree_traits_speed<unsigned int, Slots> > btree_type;
+
+ btree_type bt;
+
+ Test_BtreeSet_Find(unsigned int insertnum)
+ {
+ srand(randseed);
+ for(unsigned int i = 0; i < insertnum; i++)
+ bt.insert(rand());
+
+ assert( bt.size() == insertnum );
+ }
+
+ void run(unsigned int insertnum)
+ {
+ srand(randseed);
+ for(unsigned int i = 0; i < insertnum; i++)
+ bt.exists(rand());
+ }
+};
+
+unsigned int repeatuntil;
+
+/// Repeat (short) tests until enough time elapsed and divide by the runs.
+template <typename TestClass>
+void testrunner_loop(std::ostream& os, unsigned int insertnum, unsigned int slots)
+{
+ unsigned int runs = 0;
+ double ts1, ts2;
+
+ do
+ {
+ runs = 0; // count repetition of timed tests
+
+ {
+ TestClass test(insertnum); // initialize test structures
+
+ ts1 = timestamp();
+
+ for(unsigned int totaltests = 0; totaltests <= repeatuntil; totaltests += insertnum)
+ {
+ test.run(insertnum); // run timed test procedure
+ ++runs;
+ }
+
+ ts2 = timestamp();
+ }
+
+ std::cerr << "insertnum=" << insertnum << " slots=" << slots << " repeat=" << (repeatuntil / insertnum) << " time=" << (ts2 - ts1) << "\n";
+
+ // discard and repeat if test took less than one second.
+ if ((ts2 - ts1) < 1.0) repeatuntil *= 2;
+ }
+ while ((ts2 - ts1) < 1.0);
+
+ os << std::fixed << std::setprecision(10) << insertnum << " " << slots << " " << ((ts2 - ts1) / runs) << std::endl;
+}
+
+// Template magic to emulate a for_each slots. These templates will roll-out
+// btree instantiations for each of the Low-High leaf/inner slot numbers.
+template< template<int Slots> class functional, int Low, int High>
+struct test_range
+{
+ inline void operator()(std::ostream& os, unsigned int insertnum)
+ {
+ testrunner_loop< functional<Low> >(os, insertnum, Low);
+ test_range<functional, Low+8, High>()(os, insertnum);
+ }
+};
+
+template< template<int Slots> class functional, int Low>
+struct test_range<functional, Low, Low>
+{
+ inline void operator()(std::ostream& os, unsigned int insertnum)
+ {
+ testrunner_loop< functional<Low> >(os, insertnum, Low);
+ }
+};
+
+/// Speed test them!
+int main()
+{
+/*
+ { // Set - speed test only insertion
+
+ std::ofstream os("tune-set-insert.txt");
+
+ std::cerr << "set: insert " << insertnum << "\n";
+ repeatuntil = insertnum;
+
+ test_range<Test_BtreeSet_Insert, min_nodeslots, max_nodeslots>()(os, insertnum);
+ }
+
+ { // Set - speed test insert, find and delete
+
+ std::ofstream os("tune-set-all.txt");
+
+ std::cerr << "set: insert, find, delete " << insertnum << "\n";
+ repeatuntil = insertnum;
+
+ test_range<Test_BtreeSet_InsertFindDelete, min_nodeslots, max_nodeslots>()(os, insertnum);
+ }
+*/
+ { // Set - speed test find only
+
+ std::ofstream os("tune-set-find.txt");
+
+ std::cerr << "set: find " << insertnum << "\n";
+ repeatuntil = insertnum;
+
+ test_range<Test_BtreeSet_Find, min_nodeslots, max_nodeslots>()(os, insertnum);
+ }
+
+ return 0;
+}

0 comments on commit 1be7adb

Please sign in to comment.