Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 497537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:47:27+00:00 2026-05-13T05:47:27+00:00

I read an article about the performance of the string methods a + b

  • 0

I read an article about the performance of the string methods "a" + b versus string.Format(“a{1}”, b) and decided to make a test.

There is my code in a WinForms application(VS 2005, but interested in both 2005/2008).

    private void button1_Click(object sender, EventArgs e)
    {
        Stopwatch stopwatch = new Stopwatch();

        stopwatch.Start();
        for (int i = 0; i < 10000; i++)
        {
            Console.Write("1" + 2 + "3" + 4 + "5");
        }
        stopwatch.Stop();
        Console.WriteLine("**********");
        Console.WriteLine("'A'+'B'+'C'... 10 000 elapsed: {0}", 
            stopwatch.Elapsed.ToString());
        Console.WriteLine("**********");
        stopwatch.Reset();

        stopwatch.Start();
        for (int i = 0; i < 10000; i++)
        {
            Console.Write(string.Format("1{0}3{1}5", 2, 4));
        }
        stopwatch.Stop();
        Console.WriteLine("**********");
        Console.WriteLine("string.Format((A)B(C)...) 10 000 elapsed: {0}", 
            stopwatch.Elapsed.ToString());
        Console.WriteLine("**********");

    }

on my machine the output is the following:


12345123451234512345123451234512345123451234512345123451…

‘A’+’B’+’C’… 10 000 elapsed: 00:00:0 9.4217880


12345123451234512345123451234512345123451234512345123451…

string.Format((A)B(C)…) 10 000 elapsed: 00:00:0 9.8507060


So, the time is almost the same.

Now, I wonder how much memory I used. Is there a way to compare the memory usage and the GarbageCollector work?

I downloaded a trial .NET Memory Profiler… but maybe there is a more simple(code like above) way to detect the spent memory on both iterations?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:47:27+00:00Added an answer on May 13, 2026 at 5:47 am

    GC.GetTotalMemory might be accurate enough:

    http://msdn.microsoft.com/en-us/library/system.gc.gettotalmemory.aspx

    Otherwise, you could use the CLR GC Heap performance counters via System.Diagnostics.PerformanceCounter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this article about javasccript performance on string concatenation and scope variable so
I've read some article about String.Empty vs and I also do test by my
I've read an article about 20 top jQuery tips that uses the below code
I read an article about a month ago about a couple of methods you
I just read an article in the BlackBerry docs about writing efficient code in
Hi is there good tutorial about using Fluent Nhibernate in asp.net/winforms application ? I
I read the article about using a TabControl on Windows Phone application. I can
I read an article about a regular expression to detect base64 but when I
I read an article about using CLR integration in sqlserver and was wondering what
I've read an article about the Named Loop Idiom in C++ : http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Named_Loop This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.