Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » String::Cat optimization
Re: String::Cat optimization [message #34583 is a reply to message #34577] Wed, 30 November 2011 21:15 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
dolik.rce wrote on Wed, 30 November 2011 12:17

Huh... and I always thought memcpy is the fastest way to copy things Shocked

Any ideas how does the compiler optimization magic works in this case? I'd like to understand, it might be useful in other situations as well.

Honza


Seriously, I am really ambiguos about this optimization, it is really border case. Plus I have only tested with MSC.

Anyway, looking at assembly code, memcpy is really optimized pretty well, but spends a lot of time detecting heavy-lifting scenario (like target and source both aligned etc...), whereas String is all about adding small pieces of data.

The switch leads to simple jump to 'multiplied' position and then 'linear' code up to end. It is a very little bit faster..

All in all, perhaps more data are needed. It should be easy to #ifdef svo_memcpy to regular memcpy...

My benchmarking code was something like this:

	String str;
	for(int i = 0; i < 10000000; i++) {
		str.Clear();
		RTIMING("Cat 18");
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
	}
	for(int i = 0; i < 10000000; i++) {
		str.Clear();
		RTIMING("Cat 40");
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
		str.Cat("Hello", 5);
	}


before optimization

TIMING Cat 40         :  1.98 s  - 198.46 ns ( 2.17 s  / 10000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 10000000
TIMING Cat 18         : 591.60 ms - 59.16 ns (772.00 ms / 10000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 10000000


after

TIMING Cat 40         :  1.48 s  - 148.37 ns ( 1.68 s  / 10000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 10000000
TIMING Cat 18         : 482.71 ms - 48.27 ns (676.00 ms / 10000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 10000000

[Updated on: Wed, 30 November 2011 21:16]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Please update sources
Next Topic: New GDB frontend for Theide
Goto Forum:
  


Current Time: Tue Jun 04 21:59:43 CEST 2024

Total time taken to generate the page: 0.02105 seconds