mef.pl

来自「Oracle optimizing performance things」· PL 代码 · 共 39 行

PL
39
字号
#!/usr/bin/perl

# $Header: /home/cvs/cvm-book1/measurement\040intrusion/mef.pl,v 1.4 2003/03/19 04:38:48 cvm Exp $
# Cary Millsap (cary.millsap@hotsos.com)
# Copyright (c) 2003 by Hotsos Enterprises, Ltd. All rights reserved.

use strict;
use warnings;
use Time::HiRes qw(gettimeofday);

sub fnum($;$$) {
    # return string representation of numeric value in
    # %.${precision}f format with specified separators
    my ($text, $precision, $separator) = @_;
    $precision = 0   unless defined $precision;
    $separator = "," unless defined $separator;
    $text = reverse sprintf "%.${precision}f", $text;
    $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1$separator/g;
    return scalar reverse $text;
}

my ($min, $max) = (100, 0);
my $sum = 0;
print "How many iterations? "; my $n = <>;
print "Enter 'y' if you want to see all the data: "; my $all = <>;
for (1 .. $n) {
    my ($s0, $m0) = gettimeofday;
    my ($s1, $m1) = gettimeofday;
    my $sec = ($s1 - $s0) + ($m1 - $m0)/1E6;
    printf "%0.6f\n", $sec if $all =~ /y/i;
    $min = $sec if $sec < $min;
    $max = $sec if $sec > $max;
    $sum += $sec;
}
printf "gettimeofday latency for %s samples\n", fnum($n);
printf "\t%0.6f    seconds minimum\n", $min;
printf "\t%0.6f    seconds maximum\n", $max;
printf "\t%0.9f seconds average\n", $sum/$n;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?