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 6216379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:14:30+00:00 2026-05-24T07:14:30+00:00

I often have to write code that I would like to optimize for performance,

  • 0

I often have to write code that I would like to optimize for performance, and I often have several solutions to a particular problem.

Is there a simple way to determine the number of CPU cycles a particular statement/function would take? I’m not talking about complex code that access the file system, Windows APIs or the network, I’m talking about comparing half a dozen lines of C++ code to determine which code would be more efficient.

The classic example would be comparing ++i with i++. The former is faster, but without knowing that, how would I be able to determine this myself?

I’d rather not install costly performance tools (e.g. Intel’s tools), but find a simple way to get to the bottom. Is there a way to see the Assembler code that is generated by C++ code – without debugging?

Any other suggestions and/or approaches are of course welcome.

  • 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-24T07:14:30+00:00Added an answer on May 24, 2026 at 7:14 am

    Using the Visual Studio prompt you can invoke cl.exe (the VC++) compiler and produce assembly listings with the option /FA[c|s|u].

    cl.exe /FA mycode.c
    

    Generates a file named mycode.asm, containing the listings, looking something like:

    ; Line 16
        push    ebp
        mov ebp, esp
    ; Line 17
        cmp DWORD PTR _argc$[ebp], 2
        jl  SHORT $LN2@main
        cmp DWORD PTR _argc$[ebp], 2
        jle SHORT $LN3@main
    $LN2@main:
    ; Line 19
        push    OFFSET $SG2660
        call    _puts
        add esp, 4
    

    … and so forth.

    Similarly if you put a breakpoint inside VS and open the disassembly, you will see the assembly listings (provided the circumstances are right, debug mode should probably be on.)

    This is probably of interest as well: How many CPU cycles are needed for each assembly instruction?

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

Sidebar

Related Questions

I often find I want to write code something like this in C#, but
Preamble Using VTK library with C++, quite often I have to write something like
When I use an imperative language I often write code like foo (x) {
I have some Code that I'd like to share between an iOS and an
I'm using Squirrel SQL with Oracle. I often have to write quick queries for
I often have data in Excel or text that I need to get into
I often have a subroutine in Perl that fills an array with some information.
I often have customer requesting changing properties, like the version history setting on all
I often have to deal with XML documents that contain namespaced elements, but doesn't
I have found that I often have to implement some sort of a scheduler

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.