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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:27:57+00:00 2026-06-02T20:27:57+00:00

I wrote this little program in c++ to in order check CPU load scenarios.

  • 0

I wrote this little program in c++ to in order check CPU load scenarios.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
int main()
{

    double x = 1;
    int t1 = GetTickCount();
    srand(10000);

    for (unsigned long i = 0; i < 10000000; i++)
    {
        int r = rand();
        double l = sqrt((double)r);
        x *= log(l/3) * pow(x, r);
    }

    int t2 = GetTickCount();
    printf("Time: %d\r\n", t2-t1);
    getchar();
}

I compiled it both for x86 and for x64 on win7 x64.
For some reason when I ran the x64 version it finished running in about 3 seconds
but when I tried it with the x86 version it took 48 (!!!) seconds.
I tried it many times and always got similar results.
What could cause this difference?

  • 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-06-02T20:27:59+00:00Added an answer on June 2, 2026 at 8:27 pm

    Looking at the assembler output with /Ox (maximum optimizations), the speed difference between the x86 and x64 build is obvious:

    ; cl /Ox /Fa tick.cpp
    ; x86 Line 17: x *= log(l/3) * pow(x, r)
    fld     QWORD PTR _x$[esp+32]
    mov     eax, esi
    test    esi, esi
    ; ...
    

    We see that x87 instructions are being used for this computation. Compare this to the x64 build:

    ; cl /Ox /Fa tick.cpp
    ; x64 Line 17: x *= log(l/3) * pow(x, r)
    movapd  xmm1, xmm8
    mov     ecx, ebx
    movapd  xmm5, xmm0
    test    ebx, ebx
    ; ...
    

    Now we see SSE instructions being used instead.

    You can pass /arch:SSE2 to try and massage Visual Studio 2010 to produce similar instructions, but it appears the 64bit compiler simply produces much betterfaster assembly for your task at hand.

    Finally, if you relax the floating point model the x86 and x64 perform nearly identically.

    Timings, unscientific best of 3:

    • x86, /Ox: 22704 ticks
    • x64, /Ox: 822 ticks
    • x86, /Ox /arch:SSE2: 3432 ticks
    • x64, /Ox /favor:INTEL64: 1014 ticks
    • x86, /Ox /arch:SSE2 /fp:fast: 834 ticks
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wrote a little scratch program to check the time of looping through
I have this simple little batch file program that I wrote but it fails
I am beginnner to programming. I wrote this little program to reverse a string.
I wrote this little program to illustrate my problem : int main(int argc, char*
I wrote this little function to fill a drop down list with data from
I wrote this little code std::map<int,template<class T>> map_; map_.insert(make_pair<int,message>(myMsg.id,myMsg)); but the compiler doesn't seem
First a little intro: Last year i wrote this http://dragan.yourtree.org/code/canvas-3d-graph/ Now, i want to
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote this program in C and also in erlang To practice I tried
I wrote this simple C program: int main() { int i; int count =

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.