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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:19:12+00:00 2026-06-02T00:19:12+00:00

Curious if anyone knows (or can easily test) the time it takes to reference

  • 0

Curious if anyone knows (or can easily test) the time it takes to reference and then dereference an array.

my @foo = (0..1500000);     # (~1.5M nodes).
join('',@{\@foo});          # any noticeable time difference vs join('',@foo) ?

There’s obviously no legitimate reason for this, but I’ve come across unreasonable code 🙂

  • 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-02T00:19:13+00:00Added an answer on June 2, 2026 at 12:19 am

    Benchmarks of similar tests I’ve performed gave something on the order 10 nanoseconds per deref. There’s only deref in the code you posted, so we’re talking about a 0.000,000,010s difference.


    Bah, the difference is so tiny, that I can’t even reliably tell which one is faster!

    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.04 usr +  0.02 sys =  3.06 CPU) @ 11.12/s (n=34)
     array_ref:  3 wallclock secs ( 3.13 usr +  0.00 sys =  3.13 CPU) @ 11.48/s (n=36)
    
    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.06 usr +  0.03 sys =  3.09 CPU) @ 11.33/s (n=35)
     array_ref:  3 wallclock secs ( 3.12 usr +  0.05 sys =  3.17 CPU) @ 11.37/s (n=36)
    
    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.06 usr +  0.00 sys =  3.06 CPU) @ 11.45/s (n=35)
     array_ref:  3 wallclock secs ( 3.18 usr +  0.00 sys =  3.18 CPU) @ 11.31/s (n=36)
    
    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.09 usr +  0.00 sys =  3.09 CPU) @ 11.66/s (n=36)
     array_ref:  3 wallclock secs ( 3.17 usr +  0.00 sys =  3.17 CPU) @ 11.37/s (n=36)
    

    array is faster 50% of the time, array ref is faster 50% of the time.

    use strict;
    use warnings;
    
    use Benchmark qw( timethese );
    
    my %tests = (
       array_ref => 'my $x = join("", @$foo);',
       array     => 'my $x = join("", @foo);',
    );
    
    $_ = 'use strict; use warnings; our $foo; our @foo; ' . $_
       for values(%tests);
    
    our @foo = 1..1_500_000;
    our $foo = \@foo;
    
    timethese(-3, \%tests);
    

    Here’s a better test than the one you posted. The only you posted spent less than 1% of the time doing the thing you wanted to test.

    But again, the different is so small, that it’s not measurable. Sometimes array ref appears faster, sometimes the array appears faster.

    Actual speed is actually 1000x larger than indicated.
    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.09 usr +  0.00 sys =  3.09 CPU) @ 1015.54/s (n=3136)
     array_ref:  3 wallclock secs ( 3.24 usr +  0.00 sys =  3.24 CPU) @ 1040.99/s (n=3378)
    
    Actual speed is actually 1000x larger than indicated.
    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.25 usr +  0.00 sys =  3.25 CPU) @ 1011.09/s (n=3281)
     array_ref:  3 wallclock secs ( 3.07 usr +  0.00 sys =  3.07 CPU) @ 1022.13/s (n=3141)
    
    Actual speed is actually 1000x larger than indicated.
    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.29 usr +  0.00 sys =  3.29 CPU) @ 1020.96/s (n=3361)
     array_ref:  3 wallclock secs ( 3.20 usr +  0.00 sys =  3.20 CPU) @ 1016.26/s (n=3250)
    
    Actual speed is actually 1000x larger than indicated.
    Benchmark: running array, array_ref for at least 3 CPU seconds...
         array:  3 wallclock secs ( 3.07 usr +  0.00 sys =  3.07 CPU) @ 1053.03/s (n=3237)
     array_ref:  4 wallclock secs ( 3.23 usr +  0.00 sys =  3.23 CPU) @ 1006.50/s (n=3250)
    

    Again, array is faster 50% of the time, array ref is faster 50% of the time.

    use strict;
    use warnings;
    
    use Benchmark qw( timethese );
    
    my %tests = (
       array_ref => 'my $x = join("", @$foo);',
       array     => 'my $x = join("", @foo);',
    );
    
    $_ = 'use strict; use warnings; our $foo; our @foo; for (1..1000) { '.$_.' }'
       for values(%tests);
    
    our @foo = 1..15;
    our $foo = \@foo;
    
    print("Actual speed is actually 1000x larger than indicated.\n");
    timethese(-3, \%tests);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm curious if anyone knows of a way to easily get a double border
I'm curious if anyone knows how I can save the current state of a
I am curious if anyone knows of a way I can set my .SWF
I was curious if anyone knows of any good examples of plugins that I
I'm curious if anyone knows how to move the global messages inside the content
I'm curious if anyone knows a quick way to accomplish my goal. I want
I was curious if anyone knows a way (by using a setting or a
I'm curious if anyone knows of an MVC view engine that is more sandboxed.
I'm curious to know if anyone knows of any other .Net implementations of the
I'm curious if anyone knows how I would trigger a function to run if/once

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.