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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:16:24+00:00 2026-06-15T20:16:24+00:00

This C++ program takes from 20 to 25 seconds to run on my relatively

  • 0

This C++ program takes from 20 to 25 seconds to run on my relatively slow computer:

#include <iostream>

int main()
{
int i;
double test = 456;

for (i = 0; i < 900000000; i++) {
    test = (test / 0.99999999);
}
    std::cout << "The value of test is " << test <<".\n";
    return 0;
}

This excel vba macro takes from 37 to 40 seconds to run on my relatively slow computer:

Sub Macro1()
Dim i As Long
Dim test As Double
test = 456

For i = 0 To 900000000
    test = (test / 0.99999999)
Next i

Cells(1, 1).Value = test
End Sub

Is this difference typical(of C++ vs. non-compiled languages)? What are the major factors contributing to this difference in time? Is the fact that C++ is compiled the most important factor? Thanks.

Info:

For C++ I used Code::Blocks with GCC

For VBA I used Excel 2010.

For Code::Blocks it has a built in timer in it’s console.

For excel I used a an iPhone stopwatch(didn’t feeling like using CHighResTimer http://www.ozgrid.com/forum/showthread.php?t=56900)

  • 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-15T20:16:26+00:00Added an answer on June 15, 2026 at 8:16 pm

    Your benchmark is off, the margin should be way larger.

    For instance, on my computer, the C++ code takes 7.46s (compiled without optimisations, timed with the Unix time tool); the VBA code by contrast took 46s. This is a much more realistic margin (but I wouldn’t have been surprised by an even larger one – conventional, non-optimising interpreters are usually at least a factor ten slower).

    For one thing, VBA first has to read in the code and either interpret it line by line or transform it into an intermediate representation. Nevertheless, this intermediate code representation is still interpreted, not run directly by the CPU (or did you count the compilation time in C++?).1

    In addition, VB(A) does a lot of redundant stuff in this code which is absent in C++: for instance, every single integer addition (which is implicit in your code in the incrementation of the For loop variable) is guarded against overflow. Essentially, this VB code

    i = i + 1
    

    is transformed to the following pseudo intermediate code:

    if i + 1 overflows then
        raise an overflow error
    end if
    i = i + 1
    

    … for every integer operation. That consumes quite a lot of runtime. The same goes for array (or here: cell) access operations.


    1 I think VBA uses an intermediate representation called P-code rather than line by line code interpretation.

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

Sidebar

Related Questions

This program: #include <iostream> #include <cstdlib> #include <string> int main(int argc, const char *argv[])
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
This program takes 2 numbers from user input, asks them whether they'd like to
This query currently takes about 30 seconds to run. I'd like some help speeding
Given below is program for encrypting a string. I had taken this code from
This program takes the first number in a file and indicates how many numbers
I wrote this function to communicate with an external program. Such program takes input
I am building a program that takes an input file in this format: title
there is this check-in-out program here at my workplace, it only takes the data
I have a program, that takes a long time to load. Because of 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.