From 95fa76f5f3208d913320c13a05171ecdcd7134c2 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 2 Jan 2010 10:27:26 +0000 Subject: Performance improvements when running both in multi-threaded and pre-forked HTTPD. Changed memory management to use Apache APR pools instead of ref counting pointers as it's much faster and easier to integrate with the Python and Ruby interpreters. Changed to use simple pool-based string and stream implementations instead of the STL ones, which cause a lots of mutex locks in a multi-threaded environment. Added build options to compile with threading and profiling. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@895165 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/kernel/kernel-test.cpp | 122 ++++++++++++++++------------------- 1 file changed, 54 insertions(+), 68 deletions(-) (limited to 'sca-cpp/trunk/kernel/kernel-test.cpp') diff --git a/sca-cpp/trunk/kernel/kernel-test.cpp b/sca-cpp/trunk/kernel/kernel-test.cpp index 8a5e4a704d..c4f76c13c9 100644 --- a/sca-cpp/trunk/kernel/kernel-test.cpp +++ b/sca-cpp/trunk/kernel/kernel-test.cpp @@ -24,12 +24,10 @@ */ #include -#include -#include -#include +#include "string.hpp" +#include "sstream.hpp" #include "function.hpp" #include "list.hpp" -#include "slist.hpp" #include "tree.hpp" #include "value.hpp" #include "monad.hpp" @@ -77,7 +75,10 @@ bool testLambda() { bool testLambdaGC() { resetLambdaCounters(); - testLambda(); + { + gc_scoped_pool gc; + testLambda(); + } assert(checkLambdaCounters()); return true; } @@ -87,18 +88,15 @@ int countElements = 0; struct Element { int i; - Element() : - i(0) { + Element() : i(0) { countElements++; } - Element(int i) : - i(i) { + Element(int i) : i(i) { countElements++; } - Element(const Element& o) : - i(o.i) { + Element(const Element& o) : i(o.i) { countElements++; } @@ -110,7 +108,7 @@ struct Element { return o.i == i; } }; -std::ostream& operator<<(std::ostream& out, const Element& v) { +ostream& operator<<(ostream& out, const Element& v) { out << v.i ; return out; } @@ -124,23 +122,14 @@ bool testCons() { return true; } -bool testSet() { - list l = mklist(1, 2, 3); - setCar(l, 4); - setCdr(l, mklist(5, 6)); - assert(car(l) == 4); - assert(cadr(l) == 5); - assert(caddr(l) == 6); - assert(isNil(cdddr(l))); - return true; -} - bool testListGC() { resetLambdaCounters(); resetListCounters(); countElements = 0; - testCons(); - testSet(); + { + gc_scoped_pool gc; + testCons(); + } assert(checkLambdaCounters()); assert(checkListCounters()); assert(countElements == 0); @@ -148,13 +137,13 @@ bool testListGC() { } bool testOut() { - std::ostringstream os1; + ostringstream os1; os1 << list (); - assert(os1.str() == "()"); + assert(str(os1) == "()"); - std::ostringstream os2; + ostringstream os2; os2 << mklist(1, 2, 3); - assert(os2.str() == "(1 2 3)"); + assert(str(os2) == "(1 2 3)"); return true; } @@ -180,10 +169,7 @@ bool testAppend() { assert(car(cdr(cdr(append(mklist(1), mklist(2, 3))))) == 3); assert(isNil(cdr(cdr(cdr(append(mklist(1), mklist(2, 3))))))); - list l; - l << 1 << 2 << 3; - assert(l == mklist(1, 2, 3)); - assert(list() << 1 << 2 << 3 == mklist(1, 2, 3)); + assert(list() + 1 + 2 + 3 == mklist(1, 2, 3)); return true; } @@ -196,7 +182,7 @@ struct Complex { x(x), y(y) { } }; -std::ostream& operator<<(std::ostream& out, const Complex& v) { +ostream& operator<<(ostream& out, const Complex& v) { out << "[" << v.x << ":" << v.y << "]"; return out; } @@ -266,9 +252,9 @@ bool testListRef() { } bool testAssoc() { - const list > l = mklist(mklist("x", "X"), mklist("a", "A"), mklist("y", "Y"), mklist("a", "AA")); - assert(assoc("a", l) == mklist("a", "A")); - assert(isNil(assoc("z", l))); + const list > l = mklist(mklist("x", "X"), mklist("a", "A"), mklist("y", "Y"), mklist("a", "AA")); + assert(assoc("a", l) == mklist("a", "A")); + assert(isNil(assoc("z", l))); const list > u = mklist(mklist("x", "X"), mklist("a", "A"), mklist("y", "Y"), mklist("a", "AA")); assert(assoc("a", u) == mklist("a", "A")); @@ -279,21 +265,21 @@ bool testAssoc() { } bool testZip() { - const list k = mklist("x", "a", "y", "a"); - const list v = mklist("X", "A", "Y", "AA"); - const list > z = mklist(k, v); - const list > u = mklist(mklist("x", "X"), mklist("a", "A"), mklist("y", "Y"), mklist("a", "AA")); + const list k = mklist("x", "a", "y", "a"); + const list v = mklist("X", "A", "Y", "AA"); + const list > z = mklist(k, v); + const list > u = mklist(mklist("x", "X"), mklist("a", "A"), mklist("y", "Y"), mklist("a", "AA")); assert(zip(k, v) == u); assert(unzip(u) == z); return true; } bool testTokenize() { - assert(tokenize("/", "aaa/bbb/ccc/ddd") == mklist("aaa", "bbb", "ccc", "ddd")); - assert(tokenize("/", "/bbb/ccc/ddd") == mklist("", "bbb", "ccc", "ddd")); - assert(tokenize("/", "/bbb/ccc/") == mklist("", "bbb", "ccc")); - assert(tokenize("/", "/bbb//ccc/") == mklist("", "bbb", "", "ccc")); - assert(tokenize("/", "abc/def/") == mklist("abc", "def")); + assert(tokenize("/", "aaa/bbb/ccc/ddd") == mklist("aaa", "bbb", "ccc", "ddd")); + assert(tokenize("/", "/bbb/ccc/ddd") == mklist("", "bbb", "ccc", "ddd")); + assert(tokenize("/", "/bbb/ccc/") == mklist("", "bbb", "ccc")); + assert(tokenize("/", "/bbb//ccc/") == mklist("", "bbb", "", "ccc")); + assert(tokenize("/", "abc/def/") == mklist("abc", "def")); return true; } @@ -336,13 +322,11 @@ bool testValue() { const list v = mklist(mklist("x", "X"), mklist("a", "A"), mklist("y", "Y")); assert(cadr((list >)value(v)) == mklist("a", "A")); - const value pv(gc_ptr(new value(1))); + const value pv(gc_ptr(new (gc_new()) value(1))); assert(*(gc_ptr)pv == value(1)); - const list lpv = mklist(gc_ptr(new value(1)), gc_ptr(new value(2))); + const list lpv = mklist(gc_ptr(new (gc_new()) value(1)), gc_ptr(new (gc_new()) value(2))); assert(*(gc_ptr)car(lpv) == value(1)); - *(gc_ptr)cadr(lpv) = value(3); - assert(*(gc_ptr)cadr(lpv) == value(3)); return true; } @@ -350,7 +334,10 @@ bool testValueGC() { resetLambdaCounters(); resetListCounters(); resetValueCounters(); - testValue(); + { + gc_scoped_pool gc; + testValue(); + } assert(checkValueCounters()); assert(checkLambdaCounters()); assert(checkListCounters()); @@ -371,8 +358,8 @@ bool testTree() { return true; } -const list lta(const std::string& x) { - return mklist(x.c_str(), (x + x).c_str()); +const list lta(const string& x) { + return mklist(c_str(x), c_str(x + x)); } bool testTreeAssoc() { @@ -425,7 +412,7 @@ struct nestedFibMapPerf { bool testCppPerf() { { const lambda fml = fibMapPerf(); - std::cout << "Fibonacci map test " << (time(fml, 1, 1) / 1000) << " ms" << std::endl; + cout << "Fibonacci map test " << (time(fml, 1, 1) / 1000) << " ms" << endl; } { @@ -443,7 +430,7 @@ bool testCppPerf() { }; const lambda nfml = nestedFibMapPerf(lambda(nested::fib)); - std::cout << "Nested Fibonacci map test " << (time(nfml, 1, 1) / 1000) << " ms" << std::endl; + cout << "Nested Fibonacci map test " << (time(nfml, 1, 1) / 1000) << " ms" << endl; } return true; } @@ -490,26 +477,26 @@ bool testMaybeMonad() { return true; } -const failable failableF(const int v) { +const failable failableF(const int v) { return v * 2; } -const failable failableG(const int v) { +const failable failableG(const int v) { return v * 3; } -const failable failableH(const int v) { +const failable failableH(const int v) { return failableF(v) >> failableG; } bool testFailableMonad() { - const failable m(2); + const failable m(2); assert(m >> failableF == failableF(2)); - assert((m >> success()) == m); + assert((m >> success()) == m); assert(m >> failableF >> failableG == m >> failableH); - std::cout << "Failable monad test... "; - failable ooops = mkfailure("test"); + cout << "Failable monad test... " << endl; + failable ooops = mkfailure("test"); assert(reason(ooops) == "test"); assert(ooops >> failableF >> failableG == ooops); return true; @@ -553,14 +540,14 @@ bool testStateMonad() { } bool testDynLib() { - const failable dl(dynlib(".libs/libdynlib-test" + dynlibExt)); + const failable dl(dynlib(string(".libs/libdynlib-test") + dynlibExt)); assert(hasContent(dl)); - const failable, std::string> sq(dynlambda("csquare", content(dl))); + const failable> sq(dynlambda("csquare", content(dl))); assert(hasContent(sq)); lambda l(content(sq)); assert(l(2) == 4); - const failable()>, std::string> sql(dynlambda()>("csquarel", content(dl))); + const failable()>> sql(dynlambda()>("csquarel", content(dl))); assert(hasContent(sql)); lambda()> ll(content(sql)); assert(ll()(3) == 9); @@ -570,12 +557,11 @@ bool testDynLib() { } int main() { - std::cout << "Testing..." << std::endl; + tuscany::cout << "Testing..." << tuscany::endl; tuscany::testLambda(); tuscany::testLambdaGC(); tuscany::testCons(); - tuscany::testSet(); tuscany::testListGC(); tuscany::testOut(); tuscany::testEquals(); @@ -603,7 +589,7 @@ int main() { tuscany::testStateMonad(); tuscany::testDynLib(); - std::cout << "OK" << std::endl; + tuscany::cout << "OK" << tuscany::endl; return 0; } -- cgit v1.2.3