Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C#.NET function performance

Posted on 2014-04-01
2
Medium Priority
?
169 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 2000 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 45

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

963 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