Click here to Skip to main content
15,898,938 members
Home / Discussions / C#
   

C#

 
GeneralRe: convert long->p[][] Pin
cst_kvp17-Jun-08 2:13
cst_kvp17-Jun-08 2:13 
AnswerRe: convert long->p[][] Pin
Guffa17-Jun-08 3:11
Guffa17-Jun-08 3:11 
GeneralRe: convert long->p[][] Pin
Christian Graus17-Jun-08 3:24
protectorChristian Graus17-Jun-08 3:24 
QuestionCultureInfo.CurrentCulture Pin
George_George17-Jun-08 1:59
George_George17-Jun-08 1:59 
AnswerRe: CultureInfo.CurrentCulture Pin
carbon_golem17-Jun-08 2:04
carbon_golem17-Jun-08 2:04 
GeneralRe: CultureInfo.CurrentCulture Pin
George_George17-Jun-08 2:25
George_George17-Jun-08 2:25 
GeneralRe: CultureInfo.CurrentCulture Pin
Pete O'Hanlon17-Jun-08 3:20
mvePete O'Hanlon17-Jun-08 3:20 
GeneralRe: CultureInfo.CurrentCulture Pin
carbon_golem17-Jun-08 5:35
carbon_golem17-Jun-08 5:35 
I really wanted to give the answer that they would be the same, but after checking, I found some surprising results. Here is the timing code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Globalization;

namespace CultureInfoKata {
    class Program {
        static void Main(string[] args) {

            Stopwatch st = new Stopwatch();
            CultureInfo info = CultureInfo.CurrentCulture;
            Int64 iterations = 10000000;
            Int32 trials = 20;
            TimeSpan rAverage = TimeSpan.Zero;
            TimeSpan sAverage = TimeSpan.Zero;

            for (int j = 0; j < trials; j++) {
                Console.WriteLine("***************************************");
                Console.WriteLine("Starting iteration {0}", j.ToString());
                st.Start();
                for (int i = 0; i < iterations; i++) {
                    String.Format(info, "Text");
                }
                st.Stop();
                rAverage += st.Elapsed;
                Console.WriteLine(st.Elapsed.ToString());
                st.Reset();
                st.Start();
                for (int i = 0; i < iterations; i++) {
                    String.Format(CultureInfo.CurrentCulture, "Text");
                }
                st.Stop();
                sAverage += st.Elapsed;
                Console.WriteLine(st.Elapsed.ToString());
            }
            Console.WriteLine("***************************************");
            Console.WriteLine("Overall Results:");
            Console.WriteLine("Using object reference:{0}", TimeSpan.FromMilliseconds(rAverage.TotalMilliseconds / (Double)trials).ToString());
            Console.WriteLine("Using static reference:{0}", TimeSpan.FromMilliseconds(sAverage.TotalMilliseconds / (Double)trials).ToString());

            Console.ReadLine();
        }
    }
}


And here are the results:
***************************************
Starting iteration 0
00:00:02.4918791
00:00:02.6975864
***************************************
Starting iteration 1
00:00:05.1777309
00:00:02.7060980
***************************************
Starting iteration 2
00:00:05.1796692
00:00:02.6850936
***************************************
Starting iteration 3
00:00:05.1637124
00:00:02.6671581
***************************************
Starting iteration 4
00:00:05.1498686
00:00:02.7091927
***************************************
Starting iteration 5
00:00:05.2085886
00:00:02.7085847
***************************************
Starting iteration 6
00:00:05.1934733
00:00:02.7077047
***************************************
Starting iteration 7
00:00:05.2302492
00:00:02.7350313
***************************************
Starting iteration 8
00:00:05.2383390
00:00:02.8166922
***************************************
Starting iteration 9
00:00:05.3049657
00:00:02.6893061
***************************************
Starting iteration 10
00:00:05.1531035
00:00:02.6684418
***************************************
Starting iteration 11
00:00:05.1420193
00:00:02.6652652
***************************************
Starting iteration 12
00:00:05.1462953
00:00:02.6682994
***************************************
Starting iteration 13
00:00:05.1606059
00:00:02.7505680
***************************************
Starting iteration 14
00:00:05.4113100
00:00:02.7220753
***************************************
Starting iteration 15
00:00:05.2402528
00:00:02.7108708
***************************************
Starting iteration 16
00:00:05.2144905
00:00:02.7059263
***************************************
Starting iteration 17
00:00:05.1762065
00:00:02.6729379
***************************************
Starting iteration 18
00:00:05.1473431
00:00:02.7072361
***************************************
Starting iteration 19
00:00:05.2706150
00:00:02.8438043
***************************************
Overall Results:
Using object reference:00:00:05.0700000
Using static reference:00:00:02.7120000


I'm not sure how the results from trial 0 end up being different right off hand, I'd have to have a closer look. But it seems that using the static reference is generally faster in this test presuming I've not misused or taken for granted some aspect of the testing code. I'll run my profiler on it and get back with more results.

Scott P

“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra

GeneralRe: CultureInfo.CurrentCulture Pin
carbon_golem17-Jun-08 6:03
carbon_golem17-Jun-08 6:03 
GeneralRe: CultureInfo.CurrentCulture Pin
George_George17-Jun-08 21:19
George_George17-Jun-08 21:19 
QuestionHow can i do this? Pin
cristi_alonso17-Jun-08 1:53
cristi_alonso17-Jun-08 1:53 
AnswerRe: How can i do this? Pin
Christian Graus17-Jun-08 2:06
protectorChristian Graus17-Jun-08 2:06 
GeneralRe: How can i do this? Pin
cristi_alonso17-Jun-08 17:18
cristi_alonso17-Jun-08 17:18 
Questionhelp needed with my DB project (composite formatting) Pin
klopdisselboom17-Jun-08 1:04
klopdisselboom17-Jun-08 1:04 
AnswerRe: help needed with my DB project (composite formatting) Pin
Christian Graus17-Jun-08 2:07
protectorChristian Graus17-Jun-08 2:07 
GeneralRe: help needed with my DB project (composite formatting) Pin
klopdisselboom18-Jun-08 3:52
klopdisselboom18-Jun-08 3:52 
Questionwindows forms application using workflow c# Pin
Zeyad Jalil17-Jun-08 0:58
professionalZeyad Jalil17-Jun-08 0:58 
AnswerRe: windows forms application using workflow c# Pin
Kevin McFarlane17-Jun-08 1:51
Kevin McFarlane17-Jun-08 1:51 
QuestionRe: windows forms application using workflow c# Pin
Zeyad Jalil17-Jun-08 19:32
professionalZeyad Jalil17-Jun-08 19:32 
AnswerRe: windows forms application using workflow c# Pin
Kevin McFarlane17-Jun-08 21:59
Kevin McFarlane17-Jun-08 21:59 
QuestionReportViewer: How to get current subreport title in parent report header Pin
OregonGhost17-Jun-08 0:45
OregonGhost17-Jun-08 0:45 
QuestionBusiness classes in windows application and webservice implement same interface Pin
N a v a n e e t h17-Jun-08 0:32
N a v a n e e t h17-Jun-08 0:32 
QuestionHow can I detect the decimal separator of the current host? Pin
bouli17-Jun-08 0:31
bouli17-Jun-08 0:31 
AnswerRe: How can I detect the decimal separator of the current host? PinPopular
DaveyM6917-Jun-08 0:40
professionalDaveyM6917-Jun-08 0:40 
AnswerRe: How can I detect the decimal separator of the current host? PinPopular
DaveyM6917-Jun-08 0:44
professionalDaveyM6917-Jun-08 0:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.