Solved

C#.NET function performance

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…

830 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