| 1 | #!/usr/bin/perl
|
|---|
| 2 | # Time 1000 * 1ms sleeps, ideally 1000ms total.
|
|---|
| 3 | # Typically you may see ~1100ms for 1000 1ms sleeps on metal,
|
|---|
| 4 | # and ~1400ms for 1000 1ms sleeps within virtualbox 1 vcpu,
|
|---|
| 5 | # with this particular perl script.
|
|---|
| 6 | # On metal, 100% of sleeps can fall into the <2ms bucket.
|
|---|
| 7 | # In vbox, 99% of sleeps can fall into <2ms bucket, with
|
|---|
| 8 | # up to 10-15ms maximum, with 1 vcpu. With 2+ vcpus, the
|
|---|
| 9 | # latency goes insane, I've seen 900ms for a 1ms sleep,
|
|---|
| 10 | # and 15 seconds for 1000 1ms sleeps.
|
|---|
| 11 |
|
|---|
| 12 | use Time::HiRes qw( nanosleep time );
|
|---|
| 13 | $| = 1;
|
|---|
| 14 | @c = (0,0,0, 0,0,0, 0,0,0, 0);
|
|---|
| 15 | $max = 0;
|
|---|
| 16 | $total = 0;
|
|---|
| 17 |
|
|---|
| 18 | print " <2ms <4ms <8ms <16ms <32ms <64ms <128 <256 <512 >512\n";
|
|---|
| 19 |
|
|---|
| 20 | while ($total < 100000) {
|
|---|
| 21 | $timer = time();
|
|---|
| 22 | for ($x = 0; $x<1000; ++$x) {
|
|---|
| 23 | $delta = time();
|
|---|
| 24 | nanosleep(1000000);
|
|---|
| 25 | $delta = int(1000*(time() - $delta));
|
|---|
| 26 | if ($delta < 2.0) { ++$c[0]; }
|
|---|
| 27 | elsif ($delta < 4.0) { ++$c[1]; }
|
|---|
| 28 | elsif ($delta < 8.0) { ++$c[2]; }
|
|---|
| 29 | elsif ($delta < 16.0) { ++$c[3]; }
|
|---|
| 30 | elsif ($delta < 32.0) { ++$c[4]; }
|
|---|
| 31 | elsif ($delta < 64.0) { ++$c[5]; }
|
|---|
| 32 | elsif ($delta < 128.0) { ++$c[6]; }
|
|---|
| 33 | elsif ($delta < 256.0) { ++$c[7]; }
|
|---|
| 34 | elsif ($delta < 512.0) { ++$c[8]; }
|
|---|
| 35 | else { ++$c[9]; }
|
|---|
| 36 | if ($delta > $max) { $max = $delta; }
|
|---|
| 37 | }
|
|---|
| 38 | $timer = int(1000*(time() - $timer));
|
|---|
| 39 | $total += $x;
|
|---|
| 40 | printf("%5u %5u %5u %5u %5u %5u %5u %5u %5u %5u ",
|
|---|
| 41 | $c[0], $c[1], $c[2], $c[3], $c[4], $c[5], $c[6], $c[7], $c[8], $c[9]);
|
|---|
| 42 | print "max:${max}ms iters:$total ThisLoop:${timer}ms\n";
|
|---|
| 43 | }
|
|---|