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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:46:21+00:00 2026-06-14T20:46:21+00:00

Just a disclaimer up front: this is a homework assignment; I come here because

  • 0

Just a disclaimer up front: this is a homework assignment; I come here because my (online) teach isn’t terribly responsive. That said, I think I have it all figured out except for one issue.

The assignment is to time how long it takes to create 1000 each of 3 arrays of 100000 size in different ways: Static, on the Stack, and on the Heap. I’m pretty sure I have the code right for creating the arrays. The problem I am running into is when I print avgTime to the screen, each function outputs the exact same value. So if the first function took 800ms, that time will just be repeated over for the next two functions. I think it has something to do with the scope of the avgTime variable. Any thoughts?

#include <iostream>
#include <windows.h>

using namespace std;

void fStaticArray() {
   int i = 0;
   DWORD avgTime;
   while (i<1000){
      DWORD before = GetTickCount();
      static int staticArray [100000];
      i++;
      DWORD after = GetTickCount();
      avgTime = avgTime + (after - before);
   }
   cout << "fStaticArray: " << (avgTime/1000) << "ms  ";
   //avgTime = 0;
}

void fStackArray() {
   int i = 0;
   DWORD avgTime;
   while (i < 1000) {
      DWORD before = GetTickCount();
      int stackArray [100000];
      i++;
      DWORD after = GetTickCount();
      avgTime = avgTime + (after - before);
   }
   cout << "fStackArray: " << (avgTime/1000) << "ms   ";
}

void fHeapArray() {
   int i = 0;
   DWORD avgTime;
   while (i < 1000) {
     DWORD before = GetTickCount();
     int * heapArray = new int[100000];
     i++;
     DWORD after = GetTickCount();
     avgTime = avgTime + (after - before);
   }
   cout << "fHeapArray: " << (avgTime/1000) << "ms   ";
}


int main(void) {
   fStaticArray();
   fStackArray();
   fHeapArray();
}
  • 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-14T20:46:22+00:00Added an answer on June 14, 2026 at 8:46 pm

    There is no scope problem. Two things could make output same. First, they are same value. If they are and you are not convinced try putting different sleep in all loops or make them run for different numbers and you will see they print different. Second, they may be different, but as division of two int is int so they are printing same value. Try least one argument of division to float. Before going with any of two just try printing avgValue without division. Also you may want to put GetTickCount() before and after the while loop.

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

Sidebar

Related Questions

Disclaimer: This is for a homework assignment, but the question is not regarding the
Disclaimer: I know this type of question has been asked here before, I just
Disclaimer Please don't just vote to close this because the title looks subjective, and
(Disclaimer: I am a C# guy. I've just started learning Clojure.) I understand that
Disclaimer: I'm new to unit testing and just getting my feet wet. That being
Disclaimer: I'm new to most of this I just downloaded virtualbox yesterday and installed
Disclaimer, I not do anything in particular with regards this question, just curious. Is
Disclaimer: it's just another task for beginner so I'm good with the fact that
DISCLAIMER: This is not a real-world example. It is just a theoretical question of
Disclaimer: I realize this isn't really secure - it isn't meant to be a

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.