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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:11:01+00:00 2026-05-16T05:11:01+00:00

What gives the best performance? (edited to include another option) var myVec:Vector.<Number> = new

  • 0

What gives the best performance? (edited to include another option)

var myVec:Vector.<Number> = new Vector.<Number>();

for (...)
    // Do stuff - example: myVec.push(Math.random());

// Need to empty and repopulate vector
myVec.splice(0, myVec.length);
// OR
myVec = new Vector.<Number>();
// OR 
myVec.length = 0;
  • 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-16T05:11:01+00:00Added an answer on May 16, 2026 at 5:11 am

    Using the code below I’ve found myVec = new Vector.<T>() is the fastest way.

    Output (average times in ms to empty a Vector.<Number> with 100000 random entries):

    0.679 // using splice()
    0.024 // using new Vector.<T>()
    0.115 // using .length = 0;
    

    Code:

    var myVec:Vector.<Number> = new Vector.<Number>();
    
    var emptyTime:int;
    var startTime:int;
    
    var totalEmptyTime:Number = 0;
    
    // Need to empty and repopulate vector
    const NUM_TRIALS:int = 1000;
    
    var j:int;
    for(j = 0; j < NUM_TRIALS; j++)
    {
        fillVector();
        startTime = getTimer();
        myVec.splice(0, myVec.length);
        emptyTime = getTimer() - startTime;
        totalEmptyTime += emptyTime;
    }
    
    trace(totalEmptyTime/NUM_TRIALS);
    totalEmptyTime = 0;
    // OR
    for(j = 0; j < NUM_TRIALS; j++)
    {
        fillVector();
        startTime = getTimer();
        myVec = new Vector.<Number>();
        emptyTime = getTimer() - startTime;
        totalEmptyTime += emptyTime;
    }
    
    trace(totalEmptyTime/NUM_TRIALS);
    totalEmptyTime = 0;
    // OR 
    for(j = 0; j < NUM_TRIALS; j++)
    {
        fillVector();
        startTime = getTimer();
        myVec.length = 0;
        emptyTime = getTimer() - startTime;
        totalEmptyTime += emptyTime;
    }
    
    trace(totalEmptyTime/NUM_TRIALS);
    
    function fillVector():void
    {
        for (var i:int = 0; i < 100000; i++)
            myVec.push(Math.random());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting started/familar with Subversion and was wondering which protocol gives the best
OK, probably best to give an example here of what I mean. Imagine a
I want to be able to give a best guess for what city and
I would like to to try Emacs, and want to give it the best
Given the string ThisStringHasNoSpacesButItDoesHaveCapitals what is the best way to add spaces before the
Please give me the direction of the best guidance on the Entity Framework.
Given the one-table design given below how would the following best be queried The
Given an existing valid SVG document, what's the best way to create informational popups,
Given an Item that has been appended to a Form , whats the best
What is the best way to take a given PHP object and serialize it

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.