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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:44:34+00:00 2026-06-16T07:44:34+00:00

I am running a pretty simple VB program that solves the Project Euler Problem

  • 0

I am running a pretty simple VB program that solves the Project Euler Problem 2 and I want to time the performance. My approach is:

StartTime = Timer()
Set streamer = CreateObject("Scripting.FileSystemObject")
Set writingWriter = streamer.GetStandardStream(1)
Dim n, nIterations, Temp1, Temp2, Collector
n = 4000000
nIterations = 0
Temp1 = 0
Collector = 0
Temp2 = 1

Do
    Fib = Temp1 + Temp2
    Temp2 = Temp1
    Temp1 = Fib
    Select Case Fib Mod 2
        Case 0
            Collector = Collector + Fib
    End Select
Loop Until Fib > n
EndTime = Timer()
writingWriter.WriteLine("Solution is: " & Collector)
writingWriter.WriteLine("Code took " & EndTime - StartTime & " to execute")

The first time I ran the code I got the following output (my input is also included):

C:\Dev\cscript program.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Solution is: 4613732
Code took 0.015625 to execute

Each subsequent execution (not changing anything) gives me the following:

C:\Dev\cscript program.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Solution is: 4613732
Code took 0 to execute

Can someone explain what is going on here? It seems like the Windows Console has stored the value of Fib and is simply recalling it upon execution of the code. A friend running something similar (although he’s using VBA) got the same result – each of his subsequent executions experienced a reduction in run-time.

Please note: I know this is a pretty simple approach, I’m just trying to get a feel for VB. Not a huge fan so far.

  • 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-16T07:44:35+00:00Added an answer on June 16, 2026 at 7:44 am

    The issue is not Fib. Though you do not declare it, it uses the default value as soon as it is used in a calculation. Once your script ends, it goes out of scope. The main bottleneck area for your program is this:

    Set streamer = CreateObject("Scripting.FileSystemObject")
    Set writingWriter = streamer.GetStandardStream(1)
    

    Once it runs the first time, it is able to perform the same action much faster shortly there after probably due to data cached in RAM.

    The actual calculations that you are doing in your Do loop happen so quickly that your timer is insufficiently precise to distinguish the time. You may find some of the information on this question: What can cause a program to run much faster the 2nd time? interesting. If you google something like “program runs faster the 2nd time”, you will see a lot of responses indicating caching as the culprit.

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

Sidebar

Related Questions

I have a pretty simple C program that does some cryptographic calculations using only
I'm running through a pretty simple Flash based website tutorial from ActiveTuts. Any who,
Ant seems to be pretty bad as running interactive program. So for instance, a
I am having a problem with a pretty simply program. We started off with
I'm currently working on a program that will calculate a simple interest rate and
So I was running a profiler on my (admittedly pretty simple) application in Java,
I have a C# program that fails pretty consistently. That's ok, I've created the
I have a program that is constantly running. Normally, it seems to garbage collect,
I'm running a pretty simple bash script in ubuntu but have come up with
I have a pretty simple WPF application that is used to format inputs into

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.