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

  • SEARCH
  • Home
  • 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 6928859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:14:36+00:00 2026-05-27T11:14:36+00:00

For example : Code 1: void Main() { Console.WriteLine(Some texts); } Code 2: void

  • 0

For example :
Code 1:

void Main()
{
    Console.WriteLine("Some texts");
}

Code 2:

void Main()
{
    Foo();
}

void Foo()
{
    Console.WriteLine("Some texts");
}

Does code 2 run slower than code 1 ? I though when we build the release the JIT will inline code 2 so then code 2 will run as fast as code 1. But when I test them with LinqPad I got the IL result :

Code 1:

IL_0000:  ldstr       "Some texts"
IL_0005:  call        System.Console.WriteLine

Code 2:

IL_0000:  ldarg.0     
IL_0001:  call        UserQuery.Foo

Foo:
IL_0000:  ldstr       "Some texts"
IL_0005:  call        System.Console.WriteLine
IL_000A:  ret      

As we can see the IL result in code 2 has some extra steps for calling Foo(), does this prove that code 2 run slower than code 1 ?

  • 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-27T11:14:37+00:00Added an answer on May 27, 2026 at 11:14 am

    First off, you’re looking at the IL, not the JITted assembly code. What you have shown doesn’t prove anything. You need to look at the JITted output to see if the JITter inlined the code or not. Note that the JITter differes from platform to platform (x86 vs. x64, for example) and version of the Framework to version of the Framework.

    Secondly, of course as written version two will run slower than version one. When I say “as written” I mean that this assumes that the JITter hasn’t inlined the call in version two. The extra call adds a few machine instructions which of course take a few extra cycles to execute (again, don’t forget I said “as written!”). However the difference in performance is highly extremely magnificently unlikely to be meaningful. You would have to be doing this in the tightest of loops for trillions and trillions of iterations to ever see a meaningful performance difference.

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

Sidebar

Related Questions

Code example: private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if(some condition) { comboBox.Text =
Hei, i think order by is ordering things wrongly. Example code: static void Main()
Does anyone have an example (code or a link) that will allow me to
Consider this code: static void Main(string[] args) { var persons = new List<Person> {
I have pasted some code from Jon Skeet's C# In Depth site: static void
Example code: <html> <head> <script src=jquery-1.3.2.min.js type=text/javascript></script> <script src=jquery-ui-1.7.1.custom.min.js type=text/javascript></script> </head> <body> <table border=1
Example code: #include <cstdlib> #include <iostream> using namespace std; class A { public: A(int
The example code below works as as a server process. But when I add
The example code of section 10.6, the expected result is: after several iterations, the
Is there good example code or a test project for explaining the Model–view–presenter (MVP)

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.