Try this fun perl benchmark, to test your dual core, SMP or hyperthreaded system.

Before running, make sure you have perl 5.8 with threading support compiled in.

Perl has native ithreads as of perl 5.8.

[code lang=”perl”]
#!/usr/bin/perl -w
use threads;
use strict;

my $y1=Bench->new();
print “Bencmarking multi-threadedn”;
$y1->benchmark();

print “Benchmarking single-threadedn”;
$y1->ncpu(1);
$y1->benchmark();

package Bench;

sub new ()
{
my $self = {result => 0,ncpu=>0};

my $cpus =`sysctl hw.ncpu`;
$cpus =~ /: (.*)/g;
$self->{ncpu}=$1;

my $class = shift;
bless ($self,$class);
return $self;
}

sub ncpu {
my ($self,$num) = @_;
if(defined $num) { $self->{ncpu}=$num; } else { return $self->{ncpu}; }
}

sub benchmark ()
{
my ($self)=@_;
my @thr;
for(my $i=0;$i < $self->{ncpu};$i++)
{
print “Starting thread $in”;
push @thr, threads->create(‘benchmark_thread’);
}
my $total=0;
foreach my $t (@thr)
{
$total=$total+$t->join();
}
print “Total number of insane floating point divisions in 10 seconds is “. $total . “n”;
}

sub benchmark_thread()
{
my ($y,$x)=0;
my $time1 = time();
my ($self)=@_;
while(1){
#$time2 = time();
if((time() – $time1)>= 10){last;}
else {
$x=1.00/24000000000.001;
$y++;
}
}
return $y;
}
[/code]