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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:24:35+00:00 2026-05-15T10:24:35+00:00

What will work faster? How strongly will it affect productivity? $test = new Test();

  • 0

What will work faster? How strongly will it affect productivity?

$test = new Test();
$a1 = array();
$a2 = array();
$a3 = array();

$a1[1] = $test;
$a2['qwe'] = $test;
$a3[] = $test;
  • 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-15T10:24:36+00:00Added an answer on May 15, 2026 at 10:24 am

    As no one answered, I’ve made some test

    The code:

    <?php
    
    class O
    {
    }
    
    $test = new O;
    $a1 = array();
    $a2 = array();
    $a3 = array();
    
    $start = microtime(true);
    for ($k = 0; $k < 1000000; $k++)
        $a1[1] = $test;
    $time[1] = microtime(true)-$start;
    
    $start = microtime(true);
    for ($k = 0; $k < 1000000; $k++)
        $a2['qwe'] = $test;
    $time[2] = microtime(true)-$start;
    
    $start = microtime(true);
    for ($k = 0; $k < 1000000; $k++)
        $a3[] = $test;
    $time[3] = microtime(true)-$start;
    
    
    print_r($time);
    

    The results:

    Array ( [1] => 0.18384599685669 [2] => 0.19556093215942 [3] => 0.3099570274353 )
    

    Third one is the slowest one, but mostly because it actually allocates million objects and first two overwrite object on each pass. When I modified first to $a1[$k] = $test;, the results were similar (although don’t run it on a low memory limit, say below 128MB).

    The conclusion: as we said before, it doesn’t really matter. Focus on writing code which is readable and utilizes design patterns, not on some minor optimizations.

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

Sidebar

Related Questions

What will work faster - using PEAR package or require Some_Library.php files in code?
How to optimize this line drawing routine ? Will memcpy work faster ? void
Ideally something that will work with Oracle, MS SQL Server, MySQL and Posgress.
I want to create a game that will work both locally and online. My
Does anyone know how the validation will work with V1? I'm at the crossroads,
I'm looking for a dummy SQL statement that will work from a C# SQL
I am trying to get a header that will work with Apache, IIS 6,
What is the correct syntax to create objects in javascript that will work across
I have a very simple problem and a solution that will work, but I'm
I want to provide a piece of Javascript code that will work on any

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.