$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: mconsoni_at_[hidden]
Date: 2007-06-21 21:01:50
Author: mconsoni
Date: 2007-06-21 21:01:50 EDT (Thu, 21 Jun 2007)
New Revision: 7125
URL: http://svn.boost.org/trac/boost/changeset/7125
Log:
- benchmarks/multiple_calls.cpp: new benchmark. It opens a library in both ways and then calls an implementation's
method one millon times. Times are very similar in both approaches.
- benchmarks/multiple_libraries.cpp: initial commit of a new benchmark, not finished yet. It copies two libraries
50 times and then loads them one at a time. No results yet.
- Jamfile.v2: modified to include the new examples.
Added:
   sandbox/libs/extension/benchmarks/multiple_calls.cpp
   sandbox/libs/extension/benchmarks/multiple_libraries.cpp
Text files modified: 
   sandbox/libs/extension/benchmarks/Jamfile.v2 |     6 +++++-                                  
   1 files changed, 5 insertions(+), 1 deletions(-)
Modified: sandbox/libs/extension/benchmarks/Jamfile.v2
==============================================================================
--- sandbox/libs/extension/benchmarks/Jamfile.v2	(original)
+++ sandbox/libs/extension/benchmarks/Jamfile.v2	2007-06-21 21:01:50 EDT (Thu, 21 Jun 2007)
@@ -9,15 +9,19 @@
     : requirements
       <include>../../../
       <include>$(BOOST_ROOT)
+      <toolset>gcc:<find-static-library>boost_filesystem-gcc41
       <toolset>gcc:<find-static-library>dl
     :
     ;
 
 exe PlainOldApproach : plain_old_approach.cpp ;
+exe MultipleCalls : multiple_calls.cpp ;
+exe MultipleLibraries : multiple_libraries.cpp ;
 lib PlainOldHelloWorldLib : hello_world_plain_old.cpp : <link>shared ;
+lib HelloWorldLib : ../examples/hello_world.cpp : <link>shared ;
 
 install ../bin : 
-  PlainOldApproach PlainOldHelloWorldLib
+  PlainOldApproach PlainOldHelloWorldLib HelloWorldLib
   :
  # <install-dependencies>on 
  # <install-type>EXE 
Added: sandbox/libs/extension/benchmarks/multiple_calls.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/benchmarks/multiple_calls.cpp	2007-06-21 21:01:50 EDT (Thu, 21 Jun 2007)
@@ -0,0 +1,125 @@
+/* (C) Copyright Mariano G. Consoni 2007
+ * 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)
+ */
+
+#include <boost/extension/factory_map.hpp>
+#include <boost/extension/shared_library.hpp>
+#include <boost/extension/convenience.hpp>
+#include <boost/timer.hpp>
+
+#include <iostream>
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
+
+#ifndef WINDOWS_LEAN_AND_MEAN
+#define WINDOWS_LEAN_AND_MEAN
+#endif
+
+#include <Windows.h>
+#   pragma comment(lib, "kernel32.lib")
+#else
+#include <dlfcn.h>
+#endif
+
+
+#include "../examples/word.hpp"
+
+
+int main(void)
+{
+	using namespace boost::extensions;
+
+	const unsigned int times = 1000000;
+
+	// boost.extensions style
+	boost::timer extensions_style;
+	{
+		shared_library l((std::string("libHelloWorldLib") + ".extension").c_str());
+		l.open();
+		{
+			factory_map fm;
+			functor<void, factory_map &> load_func = l.get_functor<void, factory_map &>("extension_export_word");
+			load_func(fm);
+
+			std::list<factory<word, int> > & factory_list = fm.get<word, int>();  
+		
+			for(unsigned int c = 0; c < times; ++c) {
+
+				for (std::list<factory<word, int> >::iterator current_word = factory_list.begin();
+				     current_word != factory_list.end(); ++current_word)
+				{
+					std::auto_ptr<word> word_ptr(current_word->create());
+				
+					// do something with the word
+					std::string s(word_ptr->get_val());
+					s += "\n";
+				}
+			}
+		}
+		l.close();
+	}
+	std::cout << "Boost.extensions style: " << extensions_style.elapsed() << std::endl;
+
+
+	// plain old style
+	boost::timer old_style;
+	{
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+		HMODULE library = LoadLibrary("libPlainOldHelloWorldLib.extension");
+#else
+		void *library = dlopen("libPlainOldHelloWorldLib.extension", RTLD_LAZY);
+#endif
+
+		if(library == 0) {
+			std::cerr << "Cannot open Hello World Library." << std::endl;
+			return 1;
+		}
+		{
+			typedef void (*export_words_function_type)(word **, word **);
+			export_words_function_type export_words;
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+			export_words = (export_words_function_type) GetProcAddress(library, "extension_export_words");
+#else
+			*(void **) (&export_words) = dlsym(library, "extension_export_words");
+#endif
+			
+			if(export_words == 0) {
+				std::cerr << "Cannot get exported symbol." << std::endl;
+				return 1;
+			}
+		
+
+			for(unsigned int c = 0; c < times; ++c) {
+				// retrieve the words
+				word *first_word, *second_word;
+				(*export_words)(&first_word, &second_word);
+				
+				// do something with the word
+				std::string f(first_word->get_val());
+				f += "\n";
+
+				std::string s(second_word->get_val());
+				s += "\n";
+
+				delete first_word;
+				delete second_word;
+			}
+		}
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+		FreeLibrary(library);
+#else
+		dlclose(library);
+#endif
+	}
+	std::cout << "Plain old style: " << old_style.elapsed() << std::endl;
+
+	return 0;
+}
Added: sandbox/libs/extension/benchmarks/multiple_libraries.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/benchmarks/multiple_libraries.cpp	2007-06-21 21:01:50 EDT (Thu, 21 Jun 2007)
@@ -0,0 +1,157 @@
+/* (C) Copyright Mariano G. Consoni 2007
+ * 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)
+ */
+
+#include <boost/extension/factory_map.hpp>
+#include <boost/extension/shared_library.hpp>
+#include <boost/extension/convenience.hpp>
+#include <boost/timer.hpp>
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <iostream>
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
+
+#ifndef WINDOWS_LEAN_AND_MEAN
+#define WINDOWS_LEAN_AND_MEAN
+#endif
+
+#include <Windows.h>
+#   pragma comment(lib, "kernel32.lib")
+#else
+#include <dlfcn.h>
+#endif
+
+
+#include "../examples/word.hpp"
+
+
+int main(void)
+{
+	using namespace boost::extensions;
+
+	unsigned int libs = 50;
+
+	// FIXME: functions
+	for(unsigned int i = 1; i <= libs; ++i) {
+		std::string library_copy = "libHelloWorldLib" + boost::lexical_cast<std::string>(i) + ".extension";
+		if(boost::filesystem::exists("libHelloWorldLib.extension") && !boost::filesystem::exists(library_copy)) {
+
+			boost::filesystem::copy_file("libHelloWorldLib.extension", library_copy);
+		}
+	}
+
+	for(unsigned int i = 1; i <= libs; ++i) {
+		std::string library_copy = "libPlainOldHelloWorldLib" + boost::lexical_cast<std::string>(i) + ".extension";
+		if(boost::filesystem::exists("libPlainOldHelloWorldLib.extension") && !boost::filesystem::exists(library_copy)) {
+
+			boost::filesystem::copy_file("libPlainOldHelloWorldLib.extension", library_copy);
+		}
+	}
+
+	for(unsigned int i = 1; i <= libs; ++i) {
+		std::string library_copy = "libHelloWorldLib" + boost::lexical_cast<std::string>(i) + ".extension";
+		if(boost::filesystem::exists(library_copy)) {
+			boost::filesystem::remove(library_copy);
+		}
+	}
+
+	for(unsigned int i = 1; i <= libs; ++i) {
+		std::string library_copy = "libPlainOldHelloWorldLib" + boost::lexical_cast<std::string>(i) + ".extension";
+		if(boost::filesystem::exists(library_copy)) {
+			boost::filesystem::remove(library_copy);
+		}
+	}
+
+
+/*
+
+	const unsigned int times = 1000;
+
+	// boost.extensions style
+	boost::timer extensions_style;
+	for(unsigned int c = 0; c < times; ++c) {
+
+		shared_library l((std::string("libHelloWorldLib") + ".extension").c_str());
+		l.open();
+		{
+			factory_map fm;
+			functor<void, factory_map &> load_func = l.get_functor<void, factory_map &>("extension_export_word");
+			load_func(fm);
+
+			std::list<factory<word, int> > & factory_list = fm.get<word, int>();  
+			for (std::list<factory<word, int> >::iterator current_word = factory_list.begin();
+			     current_word != factory_list.end(); ++current_word)
+			{
+				std::auto_ptr<word> word_ptr(current_word->create());
+
+				// do something with the word
+				std::string s(word_ptr->get_val());
+				s += "\n";
+			}
+		}
+		l.close();
+	}
+	std::cout << "Boost.extensions style: " << extensions_style.elapsed() << std::endl;
+
+
+	// plain old style
+	boost::timer old_style;
+	for(unsigned int c = 0; c < times; ++c) {
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+		HMODULE library = LoadLibrary("libPlainOldHelloWorldLib.extension");
+#else
+		void *library = dlopen("libPlainOldHelloWorldLib.extension", RTLD_LAZY);
+#endif
+
+		if(library == 0) {
+			std::cerr << "Cannot open Hello World Library." << std::endl;
+			return 1;
+		}
+		typedef void (*export_words_function_type)(word **, word **);
+		export_words_function_type export_words;
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+		export_words = (export_words_function_type) GetProcAddress(library, "extension_export_words");
+#else
+		*(void **) (&export_words) = dlsym(library, "extension_export_words");
+#endif
+
+		if(export_words == 0) {
+			std::cerr << "Cannot get exported symbol." << std::endl;
+			return 1;
+		}
+		
+		// retrieve the words
+		word *first_word, *second_word;
+		(*export_words)(&first_word, &second_word);
+
+		// do something with the word
+		std::string f(first_word->get_val());
+		f += "\n";
+
+		std::string s(second_word->get_val());
+		s += "\n";
+
+		delete first_word;
+		delete second_word;
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+		FreeLibrary(library);
+#else
+		dlclose(library);
+#endif
+	}
+	std::cout << "Plain old style: " << old_style.elapsed() << std::endl;
+*/
+	return 0;
+}