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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:37:07+00:00 2026-05-23T04:37:07+00:00

I wrote this sample code to check whether integer or string index is better

  • 0

I wrote this sample code to check whether integer or string index is better in perl hash.

use Time::Local;
use Time::HiRes qw/gettimeofday/;

my %string_hash;
my %int_hash;

$i_count = 100;
$j_count = 100;
$k_count = 1000;
foreach $i (0..$i_count)
{
    foreach $i (0..$j_count)
    {
        foreach $k (0..$k_count)
        {
            $i += 0;$j += 0;$k += 0;
            $int_hash{$i}->{$j}->{$k}           = 1;
            $string_hash{"$i"}->{"$j"}->{"$k"}  = 1;
        }
    }
}


my $profile = gettimeofday();
print "String hash start:$profile\n";
foreach $i (keys %string_hash)
{
    foreach $j(keys %{ $string_hash{$i} })
    {
        foreach $k(keys %{ $string_hash{$i}{$j} })
        {
            $i += 0;$j += 0;$k += 0;
            $val = $string_hash{$i}->{$j}->{$k};
        }
    }
}
printf("String hash took:%d millisec\n", (gettimeofday()-$profile)*1000);




$profile = gettimeofday();
print "Int hash start:$profile\n";
foreach $i (keys %int_hash)
{
    foreach $j(keys %{ $int_hash{$i} })
    {
        foreach $k(keys %{ $int_hash{$i}{$j} })
        {
            $i += 0;$j += 0;$k += 0;
            $val = $int_hash{$i}->{$j}->{$k};
        }
    }
}
printf("Int hash took:%d millisec\n", (gettimeofday()-$profile)*1000);

I got this output

$ perl hashs.pl
String hash start:1308199085.84375
String hash took:500 millisec
Int hash start:1308199086.34379
Int hash took:428 millisec

I am trying this in Cygwin (Windows) and Perl version is 5.10.1

I have couple of questions here
1)When we store a integer in Hash whether a hash key is computed for that or Perl uses the vale directly in the bucket?
2)Instead of storing a string if i convert the same to a integer whether i will get any performance improvements?
3)If i need to keep a 64 bit value as the key in multihash , which will give better performance bigint or keep the 64bit value as a string

  • 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-23T04:37:08+00:00Added an answer on May 23, 2026 at 4:37 am

    Hashes in Perl only ever have strings as keys. So your $int_hash‘s keys are all coerced into strings anyway, and so any difference in run time between the two versions should be negligible.

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

Sidebar

Related Questions

let's say that I have this function in Rails (I have actually :P -
I want to code an AntiVirus for learning purposes. It will be signatures-based. I
I am having a problem with the following query(if this is a duplicate question
I wrote the following jQuery plugin that is basically just a simple notification system
I have a server hosting by Blueshot. I have been using php to get
So I have to write a duplicate checker to compare two XMLs and see
I have a check_user_access_control before_filter in my ApplicationController that checks the logged user's roles
In VS2010, the managed debugging assistant will give you a pInvokeStackImbalance exception ( pInvokeStackImbalance
I have some confusion in understanding Java Security model. In my ${JDK_HOME}/jre/lib/security/java.policy file, I
Summary: Can i get registry creation, modification, and last write times like i can

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.