Solved

C#.NET function performance

Posted on 2014-04-01
2
158 Views
Last Modified: 2014-04-01
Which would result in better performance:

private decimal _amtGroup1  = 0;

_amtGroup1 += Convert.ToDecimal(string.Format("{0:C}", Convert.ToDecimal(Fields["CurrentMonthAmountFinanced"].Value.ToString())));

_amtGroup1 += System.Math.Round(Convert.ToDecimal(Fields["CurrentMonthAmountFinanced"].Value), 2);

Open in new window

0
Comment
Question by:pzozulka
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39969705
The better question to ask yourself:  Is there a significant enough difference between these two that I should care about performance?

I suspect that the second will perform better because string.Format has a lot going on under the hood.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39970052
In addition to what kaufmed has told you.
You can always just create a loop to perform the operation multiple times and time how long the loop takes by querying the system for time at start and end.
If you had a profiler you could use that to time each operation.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question