diff --git a/.monadid b/.monadid index 78e75bb43be2baf4bcc8845e2766bef8df114ff0..2f84a279dd088b6844222a5c07e051379df0e065 100644 --- a/.monadid +++ b/.monadid @@ -1,4 +1,4 @@ monad identification file This file is used for monad directory identification Built by toole1 on linux4.ews.illinois.edu -Build Date: Wed Sep 28 16:49:19 CDT 2011 +Build Date: Sun Oct 9 16:03:25 CDT 2011 diff --git a/LICENSE.txt b/LICENSE.txt index 815e70785ebe413316c679399d4725f5f7f5150b..79a48f793c5aa6db5b97f9c6bc4afd6787635dc4 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -18,10 +18,10 @@ furnished to do so, subject to the following conditions: 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. - 3. Neither the names of <NAME OF DEVELOPMENT GROUP>, <NAME OF - INSTITUTION>, nor the names of its contributors may be used to endorse - or promote products derived from this Software without specific prior - written permission. + 3. Neither the names of Jack Toole, CS 225, the University of Illinois at + Urbana-Champaign, nor the names of its contributors may be used to + endorse or promote products derived from this Software without specific + prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, diff --git a/Makefile.proxy b/Makefile.proxy index cf6e16a8957529621b2af2792b043c298b4965e2..bb125b5eef5067098dc8b80d7f0839dffb4c801d 100644 --- a/Makefile.proxy +++ b/Makefile.proxy @@ -22,7 +22,7 @@ endif $(TESTEXE): $(TESTOBJS) $(CC) $(TESTOBJS) -o $@ -.cpp.o: $(wildcard *.h) +%.o : %.cpp $(wildcard *.h) $(CC) $(CFLAGS) -c $(@:.o=.cpp) -o $@ ifndef CLEAN_TARGET diff --git a/monad b/monad index c3b8d7d3f630af1e1f4b72d16a6c8daa7caa58dc..83846faa51fad76e97b87d1a3bbeb3637d894109 100755 Binary files a/monad and b/monad differ diff --git a/pipestream.cpp b/pipestream.cpp index 5bd64ce7254af6934d31cad978507cda9e5a2e64..ea6db277c77d542cfb748c0af8da87e631699de5 100644 --- a/pipestream.cpp +++ b/pipestream.cpp @@ -140,7 +140,6 @@ sizedpipestream<buffersize> & sizedpipestream<buffersize>::operator<<(const char { if (buffersize == 0) { - cout << "WRITING\n"; writen(fds[WRITE_END], str, strlen(str)+1); return *this; } diff --git a/proxy.cpp b/proxy.cpp index af7f1507ed58bf21fb00575d51cdcfe2adef5a5a..f8b8e606dcb5099fc8d090854a26a5cc2909ff72 100644 --- a/proxy.cpp +++ b/proxy.cpp @@ -30,12 +30,6 @@ using std::pair; using namespace util; using namespace monad_shared; -namespace proxy -{ - vector<unit_test> * global_tests = NULL; - output_check_map * global_output_checks = NULL; -} - namespace opts { bool verbose = false; @@ -55,6 +49,33 @@ OUTPUT_CHECK(contains) } +namespace proxy +{ + vector<unit_test> * global_tests = NULL; + output_check_map * global_output_checks = NULL; + + double runtime_ratio[TIME_COUNT] = + { + 1.0, + 2.0, + 2.30103, // for 200/100 + 2.82842712, + 4.0, + std::numeric_limits<double>::max() + }; + const char * runtime_str[TIME_COUNT] = + { + "O(1)", + "O(n)", + "O(nlogn)", + "O(nrootn)", + "O(n^2)", + "O(infinity)" + }; +} + + + int main(int argc, char ** argv) { using namespace proxy; @@ -306,8 +327,8 @@ int RunTests::run_all_tests() int32_t RunTests::get_sum_points() { - static int32_t cached_sum = INT32_MIN; - if (cached_sum == INT32_MIN) + static int32_t cached_sum = INT_MIN; + if (cached_sum == INT_MIN) { vector<unit_test> & tests = *environment.heap_tests; int32_t points_sum = 0; diff --git a/proxy.h b/proxy.h index 70b7d07db10db5a31a8d6821e71eb47c403e86ae..09b649b0129a87193182e1c7acf44783a1a51717 100644 --- a/proxy.h +++ b/proxy.h @@ -6,11 +6,13 @@ #ifndef MONAD_PROXY_H #define MONAD_PROXY_H +#include <iostream> +#include <limits> #include <map> #include <string> #include <vector> -#include <iostream> #include <utility> + #include "pipestream.h" #include "monad_shared.h" @@ -214,8 +216,53 @@ using std::endl; #define ASSERT_OUTPUT(checkFunc, str) \ *this_test.checkstream << #checkFunc << str; +enum proxy_runtime_t +{ + CONSTANT_TIME = 0, + N_TIME, + NLOGN_TIME, + NROOTN_TIME, + N2_TIME, + INFINITE_TIME, + TIME_COUNT +}; + +namespace proxy +{ + extern double runtime_ratio[TIME_COUNT]; + extern const char * runtime_str[TIME_COUNT]; + template <typename Generator, typename Timer> + clock_t timeIterations(Generator gen, Timer timeFunctor, size_t input_size); +} + +#define ASSERT_TIME(gen, functor, expectedTime) \ + do { \ + clock_t diff200 = proxy::timeIterations(gen, functor, 200); \ + clock_t diff100 = proxy::timeIterations(gen, functor, 100); \ + double ratio = static_cast<double>(diff200)/static_cast<double>(diff100); \ + double diffFromExpected = abs(ratio - proxy::runtime_ratio[expectedTime]); \ + double diffFromWrong = abs(ratio - proxy::runtime_ratio[expectedTime + 1]); \ + if (diffFromWrong < diffFromExpected) \ + FAIL(string("Runtime was larger than ") + proxy::runtime_str[expectedTime]); \ + } while(0) + namespace proxy { +template <typename Generator, typename Timer> +clock_t timeIterations(Generator gen, Timer timeFunctor, size_t input_size) +{ + const size_t num_iterations = 1000; + std::vector<typename Generator::result_type> inputs; + for (size_t i = 0; i < num_iterations; i++) + inputs.push_back(gen(input_size)); + + clock_t starttime = clock(); + for (size_t i = 0; i < num_iterations; i++) + timeFunctor(inputs[i]); + clock_t endtime = clock(); + return endtime - starttime; +} + inline int32_t bitflags(unsigned long a, unsigned long b, unsigned long c, unsigned long d, unsigned long e) { diff --git a/util.h b/util.h index d1b10c3f377b87904a0726182035734d26a6b992..509b2b1a0d8b0373ab714124c93939bddb182917 100644 --- a/util.h +++ b/util.h @@ -1,8 +1,11 @@ #ifndef UTIL_H #define UTIL_H -#include <errno.h> +#define __STDC_LIMIT_MACROS +#include <limits.h> #include <stdint.h> + +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h>