|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60907 - in sandbox/transaction/libs/transact: perf test
From: vicente.botet_at_[hidden]
Date: 2010-03-28 20:58:45
Author: viboes
Date: 2010-03-28 20:58:44 EDT (Sun, 28 Mar 2010)
New Revision: 60907
URL: http://svn.boost.org/trac/boost/changeset/60907
Log:
Boost.Transact:
* Add Jamfile for test
* Add nesting test
* Adapt transaction_stack_unwind.cpp to minimal test environment
Added:
sandbox/transaction/libs/transact/perf/
sandbox/transaction/libs/transact/perf/nesting.cpp (contents, props changed)
sandbox/transaction/libs/transact/test/Jamfile.v2 (contents, props changed)
Text files modified:
sandbox/transaction/libs/transact/test/transaction_stack_unwind.cpp | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
Added: sandbox/transaction/libs/transact/perf/nesting.cpp
==============================================================================
--- (empty file)
+++ sandbox/transaction/libs/transact/perf/nesting.cpp 2010-03-28 20:58:44 EDT (Sun, 28 Mar 2010)
@@ -0,0 +1,287 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2010.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifdef _MSC_VER
+# pragma warning (disable : 4535) // calling _set_se_translator() requires /EHa
+#endif
+
+//~ define BOOST_TRANSACT_PERF_THREADS equal to the number of threads if test with threads
+
+#ifndef BOOST_TRANSACT_PERF_THREADS
+#define BOOST_TRANSACT_PERF_THREADS 2
+#endif
+#ifndef BOOST_TRANSACT_PERF_NUMX
+#define BOOST_TRANSACT_PERF_NUMX 100*1000
+#endif
+#ifndef BOOST_TRANSACT_PERF_ITER
+#define BOOST_TRANSACT_PERF_ITER 1
+#endif
+#ifndef BOOST_TRANSACT_PERF_STEP
+#define BOOST_TRANSACT_PERF_STEP 10
+#endif
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+#define SINGLEX "threads"
+#else
+#define SINGLEX "no_threads"
+#endif
+
+#if BOOST_TRANSACT_PERF_THREADS>1
+#define MTHREADX "multi"
+#define BOOST_TRANSACT_PERF_MTHREAD true
+#else
+#define MTHREADX "single"
+#define BOOST_TRANSACT_PERF_MTHREAD false
+#endif
+
+#include <boost/transact/simple_transaction_manager.hpp>
+#include <boost/mpl/empty_sequence.hpp>
+
+using namespace boost;
+using namespace transact;
+
+struct my_rm{
+ typedef int transaction;
+ typedef mpl::empty_sequence services;
+ struct tag{};
+ transaction begin_root_transaction(){ return 0; }
+ transaction begin_nested_transaction(transaction){ return 0; }
+ void commit_transaction(transaction){}
+ bool finish_transaction(transaction){ return false; }
+ void rollback_transaction(transaction){}
+};
+
+#define BOOST_TRANSACT_CONFIGURATION simple_transaction_manager<my_rm,BOOST_TRANSACT_PERF_MTHREAD>
+
+#include <boost/transact/language.hpp>
+
+#include <boost/thread.hpp>
+#include <boost/bind.hpp>
+#include <stdlib.h>
+
+#include <boost/chrono/stopwatches.hpp>
+#include <boost/test/minimal.hpp>
+
+using namespace std;
+using namespace boost;
+
+
+int counter;
+void act_1(int max) {
+ counter=0;
+ //~ chrono::stopwatch_reporter<chrono::stopwatch<> > _;
+
+ for (int i=0; i< max; ++i) {
+ //counter+=i;
+ }
+ //std::cout << "0/0 TX " << max << " " << counter <<std::endl;
+}
+
+void act_2(int max) {
+
+ counter=0;
+ chrono::stopwatch_reporter<chrono::stopwatch<> > _;
+
+ for (int i=0; i< max; ++i) {
+ begin_transaction {
+ //counter+=i;
+ } end_transaction;
+ }
+ std::cout << "N/0 TX "<< max << " " << counter <<std::endl;
+}
+
+void act_3(int max) {
+
+ counter=0;
+ chrono::stopwatch_reporter<chrono::stopwatch<> > _;
+
+ begin_transaction {
+ for (int i=0; i< max; ++i) {
+ begin_transaction {
+ //counter+=i;
+ } end_transaction;
+ }
+ } end_transaction;
+ std::cout << "1/N TX "<< max << " " << counter <<std::endl;
+}
+
+void act_4(int max) {
+
+ counter=0;
+ chrono::stopwatch_reporter<chrono::stopwatch<> > _;
+
+ begin_transaction {
+ for (int i=0; i< max; ++i) {
+ //counter+=i;
+ }
+ } end_transaction;
+ std::cout << "1/0 TX "<< max << " " << counter <<std::endl;
+}
+
+
+void test_1() {
+
+ int max=BOOST_TRANSACT_PERF_NUMX;
+ int iter=BOOST_TRANSACT_PERF_ITER;
+ int step=BOOST_TRANSACT_PERF_STEP;
+
+ std::cout << "MT("<<BOOST_TRANSACT_PERF_THREADS<<")" << std::endl;
+{
+ //std::cout << "*****" << std::endl;
+ int j=max;
+ for (int i=0; i< iter; ++i) {
+ //std::cout << "Main" << std::endl;
+ act_1(j);
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+ //std::cout << "Single" << std::endl;
+ thread th(bind(act_1, j));
+ th.join();
+
+#endif
+
+#if BOOST_TRANSACT_PERF_THREADS>1
+ //std::cout << "Multi" << std::endl;
+ thread th1(bind(act_1, j));
+ thread th2(bind(act_1, j));
+ th1.join();
+ th2.join();
+#endif
+ j*=step;
+ };
+}
+{
+ int j=max;
+ //~ std::cout << "*****" << std::endl;
+ for (int i=0; i< iter; ++i) {
+ //~ std::cout << "Main" << std::endl;
+ act_1(j);
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+ //~ std::cout << "Single" << std::endl;
+ thread th(bind(act_1, j));
+ th.join();
+
+#endif
+#if BOOST_TRANSACT_PERF_THREADS>1
+ //~ std::cout << "Multi" << std::endl;
+ thread th1(bind(act_1, j));
+ thread th2(bind(act_1, j));
+ th1.join();
+ th2.join();
+#endif
+ j*=step;
+ };
+}
+{
+ int j=max;
+ std::cout << "*****" << std::endl;
+ for (int i=0; i< iter; ++i) {
+ std::cout << "Main" << std::endl;
+ act_2(j);
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+ std::cout << "Single" << std::endl;
+ thread th(bind(act_2, j));
+ th.join();
+#endif
+
+#if BOOST_TRANSACT_PERF_THREADS>1
+ std::cout << "Multi" << std::endl;
+ thread th1(bind(act_2, j));
+ thread th2(bind(act_2, j));
+ th1.join();
+ th2.join();
+#endif
+ j*=step;
+ };
+}
+{
+ int j=max;
+ std::cout << "*****" << std::endl;
+ for (int i=0; i< iter; ++i) {
+ std::cout << "Main" << std::endl;
+ act_4(j);
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+ std::cout << "Single" << std::endl;
+ thread th(bind(act_4, j));
+ th.join();
+#endif
+
+#if BOOST_TRANSACT_PERF_THREADS>1
+ std::cout << "Multi" << std::endl;
+ thread th1(bind(act_4, j));
+ thread th2(bind(act_4, j));
+ th1.join();
+ th2.join();
+#endif
+ j*=step;
+ };
+}
+{
+ int j=max;
+ std::cout << "*****" << std::endl;
+ for (int i=0; i< iter; ++i) {
+ std::cout << "Main" << std::endl;
+ act_3(j);
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+ std::cout << "Single" << std::endl;
+ thread th(bind(act_3, j));
+ th.join();
+
+#if BOOST_TRANSACT_PERF_THREADS>1
+ std::cout << "Multi" << std::endl;
+ thread th1(bind(act_3, j));
+ thread th2(bind(act_3, j));
+ th1.join();
+ th2.join();
+#endif
+#endif
+ j*=step;
+ };
+}
+
+{
+ int j=max;
+ std::cout << "*****" << std::endl;
+ for (int i=0; i< iter; ++i) {
+ std::cout << "Main" << std::endl;
+ act_3(j);
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+ std::cout << "Single" << std::endl;
+ thread th(bind(act_3, j));
+ th.join();
+#endif
+
+#if BOOST_TRANSACT_PERF_THREADS>0
+ std::cout << "Multi" << std::endl;
+ thread th1(bind(act_3, j));
+ thread th2(bind(act_3, j));
+ th1.join();
+ th2.join();
+#endif
+ j*=step;
+ };
+}
+
+}
+
+int test_main(int, char *[]){
+ test_1();
+
+ return 0;
+
+}
+
Added: sandbox/transaction/libs/transact/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/transaction/libs/transact/test/Jamfile.v2 2010-03-28 20:58:44 EDT (Sun, 28 Mar 2010)
@@ -0,0 +1,55 @@
+#
+# Boost.Transact
+# Build script for tests.
+#
+# Copyright (c) 2010 Vicente J. Botet Escriba]
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+# bring in rules for testing
+import testing ;
+
+if ! $(BOOST_ROOT)
+{
+ BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
+}
+
+project
+ : requirements
+ #<library>/boost/test//boost_unit_test_framework/<link>static
+ #<library>../build//boost_transact/<link>static
+
+ <library>/boost/thread//boost_thread/<link>static
+
+ #<library>/boost/chrono//boost_chrono/<link>static
+ #<library>/boost/system//boost_system/<link>static
+ #<include>.
+ #<include>../../..
+ #<include>$BOOST_ROOT
+ #<threading>multi
+ #<variant>debug
+
+ ;
+
+#rule stm-run ( sources * )
+#{
+# return
+# [ run $(sources) : : : <link>static ]
+## [ run $(sources) ../../../../libs/thread/build//boost_thread : : : : $(sources[1]:B)_lib ]
+# ;
+#}
+
+ alias perf
+ :
+ [ run ../perf/nesting.cpp : : : <library>/boost/chrono//boost_chrono <library>/boost/system//boost_system/<link>static <link>static ]
+ ;
+
+ alias tm
+ :
+ [ run transaction_stack_unwind.cpp ]
+ ;
+
+
+ alias all
+ : tm perf
+ ;
Modified: sandbox/transaction/libs/transact/test/transaction_stack_unwind.cpp
==============================================================================
--- sandbox/transaction/libs/transact/test/transaction_stack_unwind.cpp (original)
+++ sandbox/transaction/libs/transact/test/transaction_stack_unwind.cpp 2010-03-28 20:58:44 EDT (Sun, 28 Mar 2010)
@@ -1,6 +1,17 @@
+// Copyright Stefan Strasser 2010.
+// Copyright Vicente J. Botet Escriba 2010.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#ifdef _MSC_VER
+# pragma warning (disable : 4535) // calling _set_se_translator() requires /EHa
+#endif
+
#include <boost/transact/simple_transaction_manager.hpp>
#include <boost/mpl/empty_sequence.hpp>
-#include <boost/assert.hpp>
+#include <boost/test/minimal.hpp>
using namespace boost;
using namespace transact;
@@ -25,7 +36,6 @@
int test(int contextnr){
my_tm::transaction *txs[5];
- int retried=-1;
begin_transaction{
txs[0]=&my_tm::current_transaction();
begin_transaction{
@@ -53,13 +63,15 @@
}retry{
return 0;
}end_retry;
+ return -1;
}
-int main(){
+int test_main(int, char *[]){
my_rm rm;
my_tm::connect_resource(rm);
for(int c=0;c<5;++c){
- BOOST_ASSERT( test(c) == c );
+ BOOST_REQUIRE( test(c) == c );
}
+ return 0;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk