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 |
|
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
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
|
|
|
|
|
String::Cat optimization
By: mirek on Wed, 30 November 2011 17:58
|
|
|
Re: String::Cat optimization
By: koldo on Wed, 30 November 2011 18:11
|
|
|
Re: String::Cat optimization
|
|
|
Re: String::Cat optimization
By: mirek on Wed, 30 November 2011 21:15
|
|
|
Re: String::Cat optimization
By: koldo on Thu, 01 December 2011 06:18
|
|
|
Re: String::Cat optimization
By: mirek on Thu, 01 December 2011 08:04
|
|
|
Re: String::Cat optimization
By: koldo on Thu, 01 December 2011 08:39
|
|
|
Re: String::Cat optimization
|
|
|
Re: String::Cat optimization
By: mirek on Thu, 01 December 2011 11:37
|
|
|
Re: String::Cat optimization
|
|
|
Re: String::Cat optimization
By: Tom1 on Thu, 01 December 2011 14:50
|
|
|
Re: String::Cat optimization
By: mirek on Thu, 01 December 2011 17:52
|
|
|
Re: String::Cat optimization
By: mirek on Thu, 01 December 2011 20:41
|
|
|
Re: String::Cat optimization
By: Lance on Fri, 02 December 2011 03:59
|
|
|
Re: String::Cat optimization
By: mirek on Fri, 02 December 2011 06:39
|
|
|
Re: String::Cat optimization
By: Novo on Fri, 02 December 2011 06:02
|
|
|
Re: String::Cat optimization
By: mirek on Fri, 02 December 2011 06:40
|
|
|
Re: String::Cat optimization
By: Novo on Fri, 02 December 2011 18:50
|
|
|
Re: String::Cat optimization
By: mirek on Fri, 02 December 2011 19:06
|
|
|
Re: String::Cat optimization
By: Tom1 on Fri, 02 December 2011 10:22
|
|
|
Re: String::Cat optimization
By: mirek on Fri, 02 December 2011 11:10
|
|
|
Re: String::Cat optimization
By: mirek on Wed, 16 May 2012 15:30
|
|
|
Re: String::Cat optimization
By: unodgs on Thu, 01 December 2011 14:38
|
|
|
Re: String::Cat optimization
By: Tom1 on Thu, 01 December 2011 14:54
|
|
|
Re: String::Cat optimization
By: mirek on Thu, 01 December 2011 17:51
|
Goto Forum:
Current Time: Tue Jun 04 21:59:43 CEST 2024
Total time taken to generate the page: 0.02105 seconds
|