- Announcement: "cpp-mmf" C++98 library released - 2 Updates
- What practice can get speed improvement in C++? - 8 Updates
- Serial communications problem - 1 Update
legalize+jeeves@mail.xmission.com (Richard): Aug 06 05:56PM [Please do not mail me a copy of your followup] c.milanesi.bg@gmail.com spake the secret code >I recently released the open source library "cpp-mmf": >https://github.com/carlomilanesi/cpp-mmf There's already a boost library that covers this. <http://www.boost.org/doc/libs/1_58_0/libs/iostreams/doc/classes/mapped_file.html> -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
Victor Bazarov <v.bazarov@comcast.invalid>: Aug 06 02:31PM -0400 On 8/6/2015 1:56 PM, Richard wrote: >> https://github.com/carlomilanesi/cpp-mmf > There's already a boost library that covers this. > <http://www.boost.org/doc/libs/1_58_0/libs/iostreams/doc/classes/mapped_file.html> Did you read past the second line of the announcement? The OP wrote: >> It has the same purpose and the same run-time speed of the >> "Memory-Mapped Files" Boost library, but it offers the following >> advantages: [...] V -- I do not respond to top-posted replies, please don't ask |
woodbrian77@gmail.com: Aug 05 10:24PM -0700 On Wednesday, August 5, 2015 at 3:12:27 AM UTC-5, Juha Nieminen wrote: > > http://stackoverflow.com/questions/21946447/how-much-performance-difference-when-using-string-vs-char-array > They are not doing the same thing. Formatted printing into a static buffer > is not the same thing as building a dynamic string by appending stuff. How about comparing these two programs: #include <string.h> int main () { for (int i = 0; i < 4000000; ++i){ char s[200]; ::strncpy(s, "We few; we happy few; we band of brothers.", sizeof(s)); } } and #include <string> int main () { for (int i = 0; i < 4000000; ++i){ ::std::string s = "We few; we happy few; we band of brothers."; } } uname -a Linux localhost.localdomain 4.0.4-301.fc22.x86_64 #1 SMP Thu May 21 13:10:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.1.1/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-default-libstdcxx-abi=c++98 --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 5.1.1 20150422 (Red Hat 5.1.1-1) (GCC) size oldschool stdstr text data bss dec hex filename 1504 596 4 2104 838 oldschool 1875 604 40 2519 9d7 stdstr The std::string version is over 4 times slower than the old school version on this machine and even slower on a FreeBSD machine. time ./oldschool real 0m0.085s user 0m0.084s sys 0m0.002s time ./stdstr real 0m0.365s user 0m0.363s sys 0m0.003s Brian Ebenezer Enterprises - In G-d we trust. http://webEbenezer.net |
Ian Collins <ian-news@hotmail.com>: Aug 06 05:42PM +1200 > ::std::string s = "We few; we happy few; we band of brothers."; > } > } A fairer comparison would be int main () { std::string s; for (int i = 0; i < 4000000; ++i){ s = "We few; we happy few; we band of brothers."; } } -- Ian Collins |
woodbrian77@gmail.com: Aug 05 10:53PM -0700 On Thursday, August 6, 2015 at 12:42:31 AM UTC-5, Ian Collins wrote: > s = "We few; we happy few; we band of brothers."; > } > } Here's the time for that version. time ./stdstr real 0m0.120s user 0m0.118s sys 0m0.001s In most cases I can't lift a std::string out of the loop like that though. |
woodbrian77@gmail.com: Aug 05 11:32PM -0700 On Wednesday, August 5, 2015 at 10:03:59 AM UTC-5, Bo Persson wrote: > > a number of std::string objects to arrays of char in your application. > And you don't think that actually opening the file will hide the > difference (being fractions of a microsecond)? I'm doing what I can to make things run fast. This is trading some space for some speed. That seems like a good trade off to me. I can't do much to make opening files faster. If you don't have a lot of money for hardware, software optimizations can help. Brian Ebenezer Enterprises - Bless G-d, America. http://webEbenezer.net |
"Öö Tiib" <ootiib@hot.ee>: Aug 06 12:20AM -0700 > sys 0m0.001s > In most cases I can't lift a std::string out of the loop like that > though. We run profiler on full application. We do not write code that has no input nor output in tight loops. Therefore such tests are deceiving. On all cases of composing multi-megabyte XML, JSON or the like (why else you need to copy 4 millions of texts in tight loop?) that 'strncat' and the like lose to 'string::append' and the like. We can win both by hand optimizing usage of bytes (in vector of bytes) for concrete case but that does give minor returns because the real bottle-neck is in transfer of data. So if we instead use the effort of that raw byte level tinkering to find a way to reduce the data transferred by half then the program is twice faster. |
Christopher Pisz <nospam@notanaddress.com>: Aug 06 10:10AM -0500 > sys 0m0.001s > In most cases I can't lift a std::string out of the loop like that > though. A fairer comparison would be int main () { std::string s; s.reserve(200); for (int i = 0; i < 4000000; ++i) { s = "We few; we happy few; we band of brothers."; } } -- I have chosen to troll filter/ignore all subthreads containing the words: "Rick C. Hodgins", "Flibble", and "Islam" So, I won't be able to see or respond to any such messages --- |
Bo Persson <bop@gmb.dk>: Aug 06 05:29PM +0200 On 2015-08-06 07:42, Ian Collins wrote: > s = "We few; we happy few; we band of brothers."; > } > } Or try doing this with C strings: int main () { std::string s; for (int i = 0; i < 4000000; ++i){ s += "We few; we happy few; we band of brothers."; } } Bo Persson |
woodbrian77@gmail.com: Aug 06 09:38AM -0700 On Thursday, August 6, 2015 at 10:29:38 AM UTC-5, Bo Persson wrote: > s += "We few; we happy few; we band of brothers."; > } > } No thanks. I don't want to totally stop using std::string, but I have some cases where I'm not appending anything to the initial value. Previously I was more comfortable using std::unique_ptr than I am now. I still use unique_ptr, but not as much as before. This is similar with std::string. Brian Ebenezer Enterprises http://webEbenezer.net |
"Osmium" <r124c4u102@comcast.net>: Aug 06 10:23AM -0500 "red floyd" wrote: >> another so I thought I'd give it a shot here. > I wanted to buy some meat, but the butcher was closed, so I tried to buy > some at the greengrocer's instead. He followed the most obvious alternative he could think of. And it worked for him, didn't it? I wasn't paying attention, nevertheless I saw at least three useful answers. I'm happy for him and wish him well. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment