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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:09:50+00:00 2026-05-26T13:09:50+00:00

use strict; use Time::HiRes qw[gettimeofday tv_interval]; my $start_index = int(rand(50))+100;#this value is arbitrary for

  • 0
use strict;
use Time::HiRes qw[gettimeofday tv_interval];

my $start_index = int(rand(50))+100;#this value is arbitrary for this discussion
my $duration = 75;#also arbitrary but assume it will always be several times the size of the dataset

my $hash = {};
my @dataset = qw(foo bar baz qux bob joe sue tom);
my $partial = $duration % scalar(@dataset);
my $full = ($duration - $partial) / scalar(@dataset);

my $start = [gettimeofday()];
for my $index (0..$#dataset) {
    my $w = $dataset[$index];
    for (0..$full-1) {
        my $i = $start_index + $index + (scalar(@dataset) * $_);
        $hash->{$i} = $w;
    }
}
print "  full ".tv_interval($start)." secs\n";$start = [gettimeofday()];
for my $index (0..$partial-1) {
    my $w = $dataset[$index];
    my $s = $start_index + $index + (scalar(@dataset) * $full);
    $hash->{$s} = $w;
}
print "  part ".tv_interval($start)." secs\n";$start = [gettimeofday()];

When implemented with a (much) larger dataset and duration, the above logic in the “full” loop takes 60~120 seconds to execute. Is there a more efficient method of achieving the same results?

Edit:
To give more perspective as to the size of the dataset this is used in, this performance optimization is for a signal processing program.

  • 1 1 Answer
  • 1 View
  • 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-26T13:09:51+00:00Added an answer on May 26, 2026 at 1:09 pm

    here’s the solution:

    use strict;
    use warnings;
    use Time::HiRes qw[gettimeofday tv_interval];
    
    sub min ($$) {$_[$_[0] > $_[1]]}
    
    my $start_index = int(rand(50))+100;#this value is arbitrary for this discussion
    my $duration = 75;#also arbitrary but assume it will always be several times the size of the dataset
    
    {
        my @dataset = qw(foo bar baz qux bob joe sue tom);
        my $hash = {};
        my $partial = $duration % scalar(@dataset);
        my $full = ($duration - $partial) / scalar(@dataset);
    
        my $start = [gettimeofday()];
        for my $index (0..$#dataset) {
            my $w = $dataset[$index];
            for (0..$full-1) {
                my $i = $start_index + $index + (scalar(@dataset) * $_);
                $hash->{$i} = $w;
            }
        }
        print "  full: ".tv_interval($start)." secs\n";$start = [gettimeofday()];
        for my $index (0..$partial-1) {
            my $w = $dataset[$index];
            my $s = $start_index + $index + (scalar(@dataset) * $full);
            $hash->{$s} = $w;
        }
        print "  part: ".tv_interval($start)." secs\n";$start = [gettimeofday()];
    
        #print "$_ => $hash->{$_}\n" foreach (sort {$a <=> $b} keys %$hash);
    }
    
    #############
    print "\n\n";
    #############
    
    {
        my $dataset = [qw(foo bar baz qux bob joe sue tom)];
        my $hash;
        $hash //= {};
    
        my $remaining = $duration;
        my $phase = 0;#arbitrary
        my $start = [gettimeofday()];
        while (1) {
            last unless $remaining;
            my $chunk_size = min($remaining, scalar(@$dataset) - $phase);
            #print "$chunk_size   ".($start_index+$duration-$remaining)."..".($start_index+$duration-$remaining+$chunk_size-1)."   $phase..".($phase+$chunk_size-1)."\n";
            @{$hash}{($start_index + $duration - $remaining .. $start_index + $duration - $remaining + $chunk_size - 1)} = @{$dataset}[$phase .. $phase + $chunk_size - 1];
            $remaining -= $chunk_size;
            $phase = ($phase + $chunk_size) % scalar(@$dataset);
        }
        print "  time: ".tv_interval($start)." secs\n";$start = [gettimeofday()];
    
        #print "$_ => $hash->{$_}\n" foreach (sort {$a <=> $b} keys %$hash);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running this code parsesendnotes.pl #!/usr/bin/perl use strict; use warnings; use Device::SerialPort; use Time::HiRes qw(usleep);
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;
For more information see this Example use strict; use warnings; use CGI::Simple; use DBI;
I am doing pass-by-reference like this: use strict; use warnings; sub repl { local
When I do this #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $s =
I'd like to use strict mocks, at least when developing for the first time
This code finds the difference between today and a fixed date. #!/usr/bin/perl use strict;
var add_time = function ($category) { 'use strict'; var time_element = $('<input size=7 class=time
I have a mod_perl script: use strict; use warnings FATAL => 'all'; use 5.010001;
I have the following code: use strict; function isDefined(variable) { return (typeof (window[variable]) ===

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.