From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/tests/fstring.cpp | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 src/tests/fstring.cpp (limited to 'src/tests/fstring.cpp') diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp deleted file mode 100644 index 271738c..0000000 --- a/src/tests/fstring.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "hash.h" -#include "fstring.h" - -FString genThing() -{ - FString bob; - bob.append("ab "); - bob += "cd "; - bob += "efg"; - - printf("---bob------\n%08X: %s\n", (unsigned int)bob.c_str(), bob.c_str() ); - return bob; -} - -void thing( FString str ) -{ - printf("Hey: %s\n", str.c_str() ); -} - -#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); -int main( int argc, char *argv ) -{ - FString str("th"); - - str.prepend("Hello "); - str.append("ere."); - - FString str2( str ); - pem; - str += " What's up?"; - pem; - str2 += " How are you?"; - pem; - str = str2; - pem; - - str2 = genThing(); - pem; - - str = str2; - pem; - - thing( str2 ); - thing("test."); - - printf("%d == %d\n", __calcHashCode( str ), __calcHashCode( str.c_str() ) ); -} - -- cgit v1.2.3 From 326125aee0b8cd807a6a1d158398078ff6bfb1e1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 17 May 2007 21:45:50 +0000 Subject: As evidenced by my latest test, the Bu::FString copy is actually slower than the std::string copy by a rather large margin. This seems very odd, so I'm going to do a few tests, the first one is stripping out the FString shared pointer stuff and seeing if that makes an appreciable difference. --- build.conf | 3 ++ src/fstring.h | 4 +- src/old/tests/fstring.cpp | 48 ----------------- src/tests/fstring.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 49 deletions(-) delete mode 100644 src/old/tests/fstring.cpp create mode 100644 src/tests/fstring.cpp (limited to 'src/tests/fstring.cpp') diff --git a/build.conf b/build.conf index c289205..35738e3 100644 --- a/build.conf +++ b/build.conf @@ -6,6 +6,9 @@ default action: check group "lnhdrs", check "libbu++.a" set "CXXFLAGS" += "-ggdb -Wall" +#set "CXXFLAGS" += "-pg" +#set "LDFLAGS" += "-pg" + filesIn("src") filter regexp("^src/(.*)\\.h$", "src/bu/{re:1}.h"): rule "hln", group "lnhdrs", diff --git a/src/fstring.h b/src/fstring.h index f738f63..43033b8 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -7,6 +7,8 @@ #include "archive.h" #include "hash.h" +#define min( a, b ) ((a @@ -131,7 +133,7 @@ namespace Bu appendChunk( pNew ); } - void append( const chr cData ) + void append( const chr &cData ) { append( &cData, 1 ); } diff --git a/src/old/tests/fstring.cpp b/src/old/tests/fstring.cpp deleted file mode 100644 index 271738c..0000000 --- a/src/old/tests/fstring.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "hash.h" -#include "fstring.h" - -FString genThing() -{ - FString bob; - bob.append("ab "); - bob += "cd "; - bob += "efg"; - - printf("---bob------\n%08X: %s\n", (unsigned int)bob.c_str(), bob.c_str() ); - return bob; -} - -void thing( FString str ) -{ - printf("Hey: %s\n", str.c_str() ); -} - -#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); -int main( int argc, char *argv ) -{ - FString str("th"); - - str.prepend("Hello "); - str.append("ere."); - - FString str2( str ); - pem; - str += " What's up?"; - pem; - str2 += " How are you?"; - pem; - str = str2; - pem; - - str2 = genThing(); - pem; - - str = str2; - pem; - - thing( str2 ); - thing("test."); - - printf("%d == %d\n", __calcHashCode( str ), __calcHashCode( str.c_str() ) ); -} - diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp new file mode 100644 index 0000000..d600be6 --- /dev/null +++ b/src/tests/fstring.cpp @@ -0,0 +1,130 @@ +#include "bu/hash.h" +#include "bu/fstring.h" +#include +#include + +inline double getTime() +{ + struct timeval tv; + gettimeofday( &tv, NULL ); + return ((double)tv.tv_sec) + ((double)tv.tv_usec/1000000.0); +} + +Bu::FString genThing() +{ + Bu::FString bob; + bob.append("ab "); + bob += "cd "; + bob += "efg"; + + printf("---bob------\n%08X: %s\n", (unsigned int)bob.c_str(), bob.c_str() ); + return bob; +} + +void thing( Bu::FString str ) +{ + printf("Hey: %s\n", str.c_str() ); +} + +void copyfunc( std::string temp ) +{ + temp += "Hi"; +} + +void copyfunc( Bu::FString temp ) +{ + temp += "Hi"; +} + +void doTimings() +{ + Bu::FString fs1, fs2; + std::string ss1, ss2; + double dStart, dEnd, tfs1, tfs2, tfs3, tss1, tss2, tss3; + int nChars = 500000, nChunks=5000, nCopies=5000000, nChunkSize=1024*4; + char *buf = new char[nChunkSize]; + memset( buf, '!', nChunkSize ); + + printf("Timing Bu::FString single chars...\n"); + dStart = getTime(); + for( int j = 0; j < nChars; j++ ) fs1 += (char)('a'+(j%26)); + fs1.getStr(); + dEnd = getTime(); + tfs1 = dEnd-dStart; + + printf("Timing std::string single chars...\n"); + dStart = getTime(); + for( int j = 0; j < nChars; j++ ) ss1 += (char)('a'+(j%26)); + ss1.c_str(); + dEnd = getTime(); + tss1 = dEnd-dStart; + + printf("Timing Bu::FString %d char chunks...\n", nChunkSize); + dStart = getTime(); + for( int j = 0; j < nChunks; j++ ) fs2.append(buf, nChunkSize); + fs2.getStr(); + dEnd = getTime(); + tfs2 = dEnd-dStart; + + printf("Timing std::string %d char chunks...\n", nChunkSize); + dStart = getTime(); + for( int j = 0; j < nChunks; j++ ) ss2.append(buf, nChunkSize); + ss2.c_str(); + dEnd = getTime(); + tss2 = dEnd-dStart; + + fs2 = "Hello there."; + ss2 = "Hello there."; + printf("Timing Bu::FString copies...\n"); + dStart = getTime(); + for( int j = 0; j < nCopies; j++ ) Bu::FString stmp = fs2; + dEnd = getTime(); + tfs3 = dEnd-dStart; + + printf("Timing std::string copies...\n"); + dStart = getTime(); + for( int j = 0; j < nCopies; j++ ) std::string stpm = ss2; + dEnd = getTime(); + tss3 = dEnd-dStart; + + printf( + "Results: singles: chunks: copies:\n" + "Bu::FString %10.2f/s %10.2f/s %10.2f/s\n" + "std::string %10.2f/s %10.2f/s %10.2f/s\n", + nChars/tfs1, nChunks/tfs2, nCopies/tfs3, + nChars/tss1, nChunks/tss2, nCopies/tss3 ); + + delete[] buf; +} + +#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); +int main( int argc, char *argv ) +{ + Bu::FString str("th"); + + str.prepend("Hello "); + str.append("ere."); + + Bu::FString str2( str ); + pem; + str += " What's up?"; + pem; + str2 += " How are you?"; + pem; + str = str2; + pem; + + str2 = genThing(); + pem; + + str = str2; + pem; + + thing( str2 ); + thing("test."); + + printf("%d == %d\n", Bu::__calcHashCode( str ), Bu::__calcHashCode( str.c_str() ) ); + + doTimings(); +} + -- cgit v1.2.3 From 2b0fa89df615cb4789668014475ae64d99e773b5 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 19 Jun 2007 06:05:55 +0000 Subject: david - got some things compiling on win32 (wine/devc++) --- fstringtest.dev | 59 ++++++++++++++ libbu++.dev | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/file.cpp | 10 ++- src/file.h | 2 + src/tests/fstring.cpp | 10 +++ 5 files changed, 286 insertions(+), 4 deletions(-) create mode 100644 fstringtest.dev create mode 100644 libbu++.dev (limited to 'src/tests/fstring.cpp') diff --git a/fstringtest.dev b/fstringtest.dev new file mode 100644 index 0000000..297242d --- /dev/null +++ b/fstringtest.dev @@ -0,0 +1,59 @@ +[Project] +FileName=fstringtest.dev +Name=fstringtest +UnitCount=1 +Type=1 +Ver=1 +ObjFiles= +Includes=z:\home\neonphog\wine_documents\libbu++\src\bu +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler=_@@_ +Linker=libbu++.a_@@_ +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +OverrideOutput=0 +OverrideOutputName=fstringtest.exe +HostApplication= +Folders= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit1] +FileName=src\tests\fstring.cpp +CompileCpp=1 +Folder=fstringtest +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/libbu++.dev b/libbu++.dev new file mode 100644 index 0000000..2fb1ae9 --- /dev/null +++ b/libbu++.dev @@ -0,0 +1,209 @@ +[Project] +FileName=libbu++.dev +Name=libbu++ +UnitCount=16 +Type=2 +Ver=1 +ObjFiles= +Includes=z:\home\neonphog\wine_documents\libbu++\src\bu +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +OverrideOutput=0 +OverrideOutputName=libbu++.a +HostApplication= +Folders= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 + +[Unit1] +FileName=src\stream.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit2] +FileName=src\stream.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=src\file.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=src\file.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=src\fstring.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=src\fstring.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=src\archival.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=src\archival.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=src\archive.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=src\archive.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=src\hash.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=src\hash.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=src\exceptionbase.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit14] +FileName=src\exceptionbase.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit15] +FileName=src\list.cpp +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit16] +FileName=src\list.h +CompileCpp=1 +Folder=libbu++ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/src/file.cpp b/src/file.cpp index 368b788..1a8bd08 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -134,19 +134,21 @@ void Bu::File::setBlocking( bool bBlocking ) return; } +#ifndef WIN32 void Bu::File::truncate( long nSize ) { ftruncate( fileno( fh ), nSize ); } -void Bu::File::flush() +void Bu::File::chmod( mode_t t ) { - fflush( fh ); + fchmod( fileno( fh ), t ); } +#endif -void Bu::File::chmod( mode_t t ) +void Bu::File::flush() { - fchmod( fileno( fh ), t ); + fflush( fh ); } bool Bu::File::isOpen() diff --git a/src/file.h b/src/file.h index 1a4421b..0f638a7 100644 --- a/src/file.h +++ b/src/file.h @@ -47,6 +47,7 @@ namespace Bu *@param sFlags (const char *) Standard file flags 'rb'... etc.. *@returns (Bu::File) A file object representing your temp file. */ +#ifndef WIN32 inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) { int afh_d = mkstemp( sName.getStr() ); @@ -66,6 +67,7 @@ namespace Bu *@param t (mode_t) The new file access permissions. */ void chmod( mode_t t ); +#endif private: FILE *fh; diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp index d600be6..48dfc5f 100644 --- a/src/tests/fstring.cpp +++ b/src/tests/fstring.cpp @@ -3,12 +3,22 @@ #include #include +#ifndef WIN32 inline double getTime() { struct timeval tv; gettimeofday( &tv, NULL ); return ((double)tv.tv_sec) + ((double)tv.tv_usec/1000000.0); } +#else +#include "windows.h" +#include "winbase.h" +inline double getTime() +{ + uint32_t t = (uint32_t) GetTickCount(); + return (double) t / 1000.0; +} +#endif Bu::FString genThing() { -- cgit v1.2.3