speed of csharp

This is a discussion on speed of csharp within the C# Programming forums, part of the General Programming Boards category; Hi, i wrote my first csharp program last night, it was just a template console hello world which i added ...

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409

    speed of csharp

    Hi, i wrote my first csharp program last night, it was just a template console hello world which i added a count variable to and output the line hello world 100 times using Console.Writeline("hello world\n" + count) i had not read up on correct syntax or output formatting as i just wanted to give it a go first.

    i was amazed to see how slow it ran, is this normal? It took a couple of seconds to complete. it was like qbasic interpreter speed

    I removed the text and just had it output the count variable, same result
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Code:
                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                watch.Start();
    
                for (int i = 0; i < 100; i++)
                {
                    Console.WriteLine("Hello " + i);
                }//for
    
                watch.Stop();
    
                Console.WriteLine("Time Elapsed: " + watch.ElapsedMilliseconds);
    
                Console.Read();
    Output from three runs
    Code:
    Time Elapsed: 70
    Time Elapsed: 49
    Time Elapsed: 67
    Computer Specs(Just in case):
    Code:
    Intel Dual Core 2.10 GHz
    4 GB Ram
    Windows 7 64 bit
    Last edited by prog-bman; 09-14-2010 at 03:41 AM.
    Woop?

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    Yes mate but given the spec of your computer i would expect even a slow executing program to run fast, I know that even on my steam powered system the same thing written in C or C++ would appear instantaneous, so why doesn't the C#? Is it because its just slower?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by rogster001 View Post
    Is it because its just slower?
    Depending on your specs, you may see some start-up time as the .Net framework assemblies are loaded into memory. However, I really don't know what kind of specs you'd need to have to see that sort of start-up time since every C# app I've written has had perfectly fine performance on every computer I've used, including my 7-year-old tower.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    It must be system then, it runs kind of like its in treacle, i actually thought i had mis-coded and was getting an infinite loop at first haha, i forced a break!

    its the .net runtime minimum only 1.1 or something i think, i should upgrade i suppose, and running sharp develop, which i am finding a bit awkward to use to say the least, practice makes perfect i suppose, anybody comment on it's usefulness?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Never used it.

    Is there a particular reason you are not using the express editions of visual studio?
    Woop?

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409

    .

    there certainly is amigo mio- no internet on my pc, the kids have laptops but its their payg download allowance and the machine i home program on is stand alone, cest la vie, me n my missus agreed no home internet a while back for various reasons, n the package depends on it to complete download, unless know a full download express location?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  8. #8
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Microsoft offers an offline installation ISO image.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409

    .

    Quote Originally Posted by pianorain View Post
    Microsoft offers an offline installation ISO image.
    hey thanks, i will look it up
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Console.WriteLine("Hello " + i);
    Console output is slow.

    Also you can use stringbuilder to create strings which might be faster or might not. But C# is plenty fast enough for what it was designed for.

  11. #11
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Code:
    using System;
    
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                int start, finish;
    
                start = Environment.TickCount;
    
                for (int i = 0; i < 100; i++)
                    Console.WriteLine("hello world " + i);
    
                finish = Environment.TickCount;
    
                Console.WriteLine("operation took " + (finish - start) + " milliseconds");
                Console.Read();
            }
        }
    }
    operation took 31 milliseconds

    That's on my i7 920 computer. What does it return on yours?
    Last edited by theoobe; 09-15-2010 at 10:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Keeping program running at constant speed.
    By twinzen in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2010, 03:15 AM
  2. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 11:29 AM
  3. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2006, 11:40 PM
  4. Replies: 6
    Last Post: 01-08-2006, 01:49 PM
  5. increased net speed
    By PING in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-29-2005, 06:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21