#!/usr/bin/perl use strict; # # This program benchmarks Cloud CPU and disk performance. # # Copyright © Chris Evans, Brookend Ltd, thestoragearchitect.com # use Benchmark; use Getopt::Long; my $help; my $version = '0.2'; my $threadcount = 1; my $iterations = 10; my $interval = 1; GetOptions('help' => \$help,'threads=i' => \$threadcount, 'iterate=i' => \$iterations, 'interval=i' => \$interval); if (defined $help) { print "Cloud CPU Performance Checker version $version \n"; print "Copyright (c) Brookend Ltd 2011 thestoragearchitect.com\n\n"; print "Usage: perl cloudperf.pl [arguments]\n\n"; print "Arguments:\n"; print " --threads= Number of threads to execute in parallel (default=1)\n"; print " --iterate= Number of iterations (loops) per thread (default=10)\n"; print " --interval= Number of whole seconds per iteration (default=1)\n"; print " --help print this message\n"; } else { print "Script is running with the following settings:\n\n"; print "Number of threads: $threadcount\n"; print "Number of iterations per thread: $iterations\n"; print "Seconds per iteration: $interval\n\n"; printf "%-10s\t%-10s\t%-6s\t%-6s\t%-6s\t%-6s\n","Iteration","PID","MFlops","Real","User","Sys"; for (my $thread = 1; $thread <= $threadcount;$thread++) { my $pid; next if $pid = fork; die "Resources unavailable. $!" unless defined $pid; &DoBenchmark; exit (0); } 1 while (wait() != -1); } sub DoBenchmark { for (my $i = 1; $i <= $iterations; $i++) { my $start = Benchmark->new; my $flopcount = 0; my $starttime = time; while (time-$starttime < $interval ) { $flopcount++; my $temp = sin log sqrt rand 1000000; } my $end = Benchmark->new; my $diff = timediff( $end, $start ); ( my $real, my $user, my $system ) = @$diff[0,1,2]; printf "%-10s\t%-10s\t%.3f\t%.3f\t%.3f\t%.3f\t\n",$i, $$, $flopcount/1000000, $real, $user, $system; } }