Solved

C#.NET function performance

Posted on 2014-04-01
2
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 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