Board index » Visual Studio » How much speed gain?

How much speed gain?

Visual Studio157
I am developing a sql server extended stored procedure. The developing tools

are VS 2005 standard, SQL Server 2005 The stored procedure will used in a

database cursor loop iterating from several million to 20 million.



I used std::vector to store the parameter class pointers (about 200). And I

used virtual method. (Base class are abstract class), template sub classes,

dynamic_cast, static_cast....



The 7M rows takes about five hours. How much speed gain if I use simple C

code to implement it?



Thanks,


-
 

Re:How much speed gain?

nick wrote:

Quote
I am developing a sql server extended stored procedure. The

developing tools are VS 2005 standard, SQL Server 2005 The stored

procedure will used in a database cursor loop iterating from several

million to 20 million.



I used std::vector to store the parameter class pointers (about 200).

And I used virtual method. (Base class are abstract class), template

sub classes, dynamic_cast, static_cast....



The 7M rows takes about five hours. How much speed gain if I use

simple C code to implement it?



Most likely, little or none at all, because most likely, code execution

speed is not your bottleneck. Do some profiling to find out where you're

spending the time before guessing at fixes.



-cd





-

Re:How much speed gain?

yes, i hope the bottlenet was the OOP part. however, the C++ do need to

execute more instructions. It seems the profiler is not included in the

standard version of VS 2005? And it sounds harder since I must configure VS

to launch SQL Server first.



(for each row)

vector.push_back: 200 times

dynamic_cast: 100 - 200 times

virtual method calls several hundred times

(I guess template should have little runtime speed issues.)



So a pure C code can remove several million of these intructions. Anyone can

give a rough number of executive time? (Consider SQL Server need to open a

cursor and read and write rows)



I will write a xslt code to automatic generate the "dumb" C code if it takes

a more than 20% of total execution time....





"Carl Daniel [VC++ MVP]" wrote:



Quote
nick wrote:

>I am developing a sql server extended stored procedure. The

>developing tools are VS 2005 standard, SQL Server 2005 The stored

>procedure will used in a database cursor loop iterating from several

>million to 20 million.

>

>I used std::vector to store the parameter class pointers (about 200).

>And I used virtual method. (Base class are abstract class), template

>sub classes, dynamic_cast, static_cast....

>

>The 7M rows takes about five hours. How much speed gain if I use

>simple C code to implement it?



Most likely, little or none at all, because most likely, code execution

speed is not your bottleneck. Do some profiling to find out where you're

spending the time before guessing at fixes.



-cd







-

Re:How much speed gain?

"nick" <nick@discussions.microsoft.com>wrote:

Quote
(for each row)

vector.push_back: 200 times

dynamic_cast: 100 - 200 times

virtual method calls several hundred times

(I guess template should have little runtime speed issues.)



So a pure C code can remove several million of these intructions. Anyone

can

give a rough number of executive time? (Consider SQL Server need to open a

cursor and read and write rows)



Daft question perhaps, but why are you pushing back onto the vector, if you

know its max size why not use a fixed array?



Presuming that you actually know what it is beforehand and the virtual

aspect is inside the loop, try implimenting your own function by pointer

calls.



Are you dynamically allocating memory? Things containing most standard

classes will do this, CString, std::string, vector etc and will have a large

performance hit on tight loops. If you can reuse what is allocated you will

save time.



Set up some timers, QueryPeformanceCounter and place them around sections of

your code to profile it.



This is all, of course, without knowing what is going on inside the virtual

functions you call.



--

- Mark Randall

www.temporal-solutions.co.uk">www.temporal-solutions.co.uk



"We're Systems and Networks..."

"It's our job to know..."





-

Re:How much speed gain?

nick wrote:

Quote
yes, i hope the bottlenet was the OOP part.



More likely the DB part.



however, the C++ do need to

Quote
execute more instructions. It seems the profiler is not included in the

standard version of VS 2005? And it sounds harder since I must configure VS

to launch SQL Server first.



(for each row)

vector.push_back: 200 times



make sure you do

v.reserve(200);

before the push_backs.



Quote
dynamic_cast: 100 - 200 times



dynamic_cast is rarely needed in well designed C++ code, and is quite

inefficient. Usually it is only needed when interfacing with other

libraries (e.g. IO libraries) in order to recover the "lost" types of

things.



Quote
virtual method calls several hundred times

(I guess template should have little runtime speed issues.)



So a pure C code can remove several million of these intructions. Anyone can

give a rough number of executive time? (Consider SQL Server need to open a

cursor and read and write rows)



I will write a xslt code to automatic generate the "dumb" C code if it takes

a more than 20% of total execution time....



Rather than consider "dumb" C code, why not:



a) find out what's slow.

b) optimize the relevant C++ code.



I don't understand why you want to throw the code away, unless it is

very badly designed (which is a possibility of course).



Typically with DB code you'll get better performance improvements by

combining queries, adding appropriate indices to the DB and batching

updates, etc.



Tom

-

Re:How much speed gain?

Thanks.



"Tom Widmer [VC++ MVP]" wrote:



Quote
>yes, i hope the bottlenet was the OOP part.

More likely the DB part.

Sorry I mean I hope the bottleneck is not OOP part.



Quote
make sure you do v.reserve(200) before the push_backs.

I didn't do this, I will try and see how much it can improve. However I

remember vector will allocate memory by trunk....



Quote
dynamic_cast is rarely needed in well designed C++ code, and is quite

inefficient. Usually it is only needed when interfacing with other

libraries (e.g. IO libraries) in order to recover the "lost" types of

things.

Most resource suggest use dynamic_cast for safer code... Anyway I will try C

type cast, which maybe faster...



Quote
Rather than consider "dumb" C code, why not:



a) find out what's slow.

b) optimize the relevant C++ code.



I don't understand why you want to throw the code away, unless it is

very badly designed (which is a possibility of course).



Typically with DB code you'll get better performance improvements by

combining queries, adding appropriate indices to the DB and batching

updates, etc.



The DB part is very simple. Open a cursor on a table and iterate row by

row....

I will try to create a T-SQL loop to call the C++ code without any database

table/cursor operation so I can isolate the issues....

-

Re:How much speed gain?

"nick" <nick@discussions.microsoft.com>wrote in message

Quote
Thanks.



"Tom Widmer [VC++ MVP]" wrote:



>>yes, i hope the bottlenet was the OOP part.

>More likely the DB part.

Sorry I mean I hope the bottleneck is not OOP part.



>make sure you do v.reserve(200) before the push_backs.

I didn't do this, I will try and see how much it can improve. However I

remember vector will allocate memory by trunk....



std::vector uses exponential growth to achieve amortized constant insertion

time. But, if you know the ultimate size in advance, using reserve will be

even faster since there's no re-allocation at all.



Quote


>dynamic_cast is rarely needed in well designed C++ code, and is quite

>inefficient. Usually it is only needed when interfacing with other

>libraries (e.g. IO libraries) in order to recover the "lost" types of

>things.

Most resource suggest use dynamic_cast for safer code... Anyway I will try

C

type cast, which maybe faster...



Dump those resources - they're giving you bad advice.



Under VC++ in particular, dynamic_cast is very slow because after tracing

through a potentially complex inheritance graph, once a potential match is

found, strcmp (yes, strcmp) is used to compare the full type name of the

types in question to determine if they're the same.



In most cases you can replace dynamic_cast with static_cast in (as Tom said)

well designed code.



-cd





-