From 7975e4139c12533d408f0e47c13e840689328b4e Mon Sep 17 00:00:00 2001
From: whh8b <whh8b@git.zephyr-software.com>
Date: Fri, 1 Jan 2016 16:11:08 +0000
Subject: [PATCH] Add range default constructor speed tests.

---
 .gitattributes     |  1 +
 test/SConscript    | 15 +++++++--
 test/ZiprRange.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 3 deletions(-)
 create mode 100644 test/ZiprRange.cpp

diff --git a/.gitattributes b/.gitattributes
index 74a34ac..9494564 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -34,6 +34,7 @@ test/SConscript -text
 test/SConstruct -text
 test/ZiprDollop.cpp -text
 test/ZiprOptions.cpp -text
+test/ZiprRange.cpp -text
 test/dylib/Makefile -text
 test/dylib/dylib.c -text
 test/dylib/dylib.h -text
diff --git a/test/SConscript b/test/SConscript
index 78548f0..daf96ce 100644
--- a/test/SConscript
+++ b/test/SConscript
@@ -14,6 +14,12 @@ MemorySpaceFiles=  '''
 	../src/zipr_options.cpp
 	'''
 
+RangeFiles=  '''
+	ZiprRange.cpp
+	../src/memory_space.cpp
+	../src/zipr_options.cpp
+	'''
+
 OptionFiles=  '''
 	ZiprOptions.cpp
 	../src/zipr_options.cpp
@@ -56,8 +62,9 @@ libpath='''
 	'''
 
 myenv.Append(CCFLAGS=" -Wall ")
-myenv.Append(CXXFLAGS=" -std=c++11 -g -O0 ")
-myenv.Append(LINKFLAGS=" -Wl,-E ")	# export all symbols
+myenv.Append(CXXFLAGS=" -pg -std=c++11 -g -O0 ")
+#myenv.Append(CXXFLAGS=" -pg -g -O0 ")
+myenv.Append(LINKFLAGS="  -pg -Wl,-E ")	# export all symbols
 
 
 myenv=myenv.Clone(CPPPATH=Split(cpppath), LIBS=Split(libs), LIBPATH=Split(libpath))
@@ -65,8 +72,10 @@ myenv=myenv.Clone(CPPPATH=Split(cpppath), LIBS=Split(libs), LIBPATH=Split(libpat
 #print 'myenv='
 #print myenv.Dump()
 
+Range=myenv.Program("Range.exe", Split(RangeFiles))
 MemorySpace=myenv.Program("MemorySpace.exe", Split(MemorySpaceFiles))
 Options=myenv.Program("Options.exe", Split(OptionFiles))
 Dollop=myenv.Program("Dollop.exe", Split(DollopFiles))
-Default([MemorySpace, Options, Dollop])
+#Default([MemorySpace, Options, Dollop, Range])
+Default([Range])
 
diff --git a/test/ZiprRange.cpp b/test/ZiprRange.cpp
new file mode 100644
index 0000000..0bef997
--- /dev/null
+++ b/test/ZiprRange.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014 - Zephyr Software LLC
+ *
+ * This file may be used and modified for non-commercial purposes as long as
+ * all copyright, permission, and nonwarranty notices are preserved.
+ * Redistribution is prohibited without prior written consent from Zephyr
+ * Software.
+ *
+ * Please contact the authors for restrictions applying to commercial use.
+ *
+ * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Author: Zephyr Software
+ * e-mail: jwd@zephyr-software.com
+ * URL   : http://www.zephyr-software.com/
+ *
+ */
+
+#include <zipr_all.h>
+#include <zipr_sdk.h>
+
+using namespace zipr;
+using namespace std;
+using namespace Zipr_SDK;
+
+#define INVOKE(a) \
+bool __ ## a ## _result = false; \
+printf("Invoking " #a ":\n"); \
+__ ## a ## _result = a(); \
+printf(#a ":"); \
+if (__ ## a ## _result) \
+{ \
+printf(" pass\n"); \
+} \
+else \
+{ \
+printf(" fail\n"); \
+}
+
+class DollopMockup {
+	private:
+		int m_size;
+	public:
+		DollopMockup() : m_size(0) {};
+		void Size(int size) { m_size = size; }
+		int Size() const { return m_size; }
+};
+
+bool TestRangeSpeed() {
+	ZiprMemorySpace_t m;
+	DollopMockup *d = new DollopMockup();
+
+	d->Size(50);
+
+	for (int i = 0;
+	     i<25;
+			 i++) {
+		m.AddFreeRange(Range_t(100*i, (100*(i+1))-1));
+	}
+
+	//m.PrintMemorySpace(cout);
+
+	for (int i = 0;
+	     i<100000000;
+			 i++)
+	{
+		volatile RangeAddress_t found_start = 0;
+		Range_t placement;
+		placement = m.GetFreeRange(d->Size());
+
+		found_start = placement.GetStart();
+	}
+
+	return true;
+}
+
+int main(int argc, char *argv[])
+{
+	INVOKE(TestRangeSpeed);
+	return 0;
+}
-- 
GitLab