Solved

C#.NET function performance

Posted on 2014-04-01
2
155 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 74

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now