Last active
December 18, 2024 04:17
-
-
Save delphinus/c72417c685fc1c2a8e35ca596cfa8fc3 to your computer and use it in GitHub Desktop.
Alternative vim-startuptime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
=head1 DESCRIPTION | |
Alternative vim-startuptime | |
=head1 SYNOPSIS | |
bench-nvim | |
# Run nvim 10 times after 1 warmup | |
bench-nvim -c 100 -w 5 | |
# Run nvim 100 times after 5 warmups | |
bench-nvim -l /tmp/foo.log | |
# Store results into /tmp/foo.log | |
bench-nvim -h | |
# See this help | |
=cut | |
use strict; | |
use warnings; | |
use Getopt::Long qw(:config posix_default no_ignore_case bundling auto_help); | |
use Path::Tiny qw(path tempfile); | |
use Pod::Usage 'pod2usage'; | |
GetOptions( | |
\my %opt, qw( | |
count|c=i | |
warmup|w=i | |
logfile|l=s | |
help|h | |
)) or pod2usage(1); | |
$opt{help} and pod2usage(0); | |
%opt = ( | |
count => 10, | |
warmup => 1, | |
%opt, | |
); | |
my $cmd = 'nvim'; | |
my $tmp = defined $opt{logfile} ? path($opt{logfile}) : tempfile; | |
for (1 .. $opt{warmup}) { | |
0 == system 'env', 'WARMUP=true', $cmd or die "$cmd failed: $!\n"; | |
} | |
for (1 .. $opt{count}) { | |
0 == system 'env', "LOGFILE=$tmp", $cmd or die "$cmd failed: $!\n"; | |
} | |
my ($sum, $max, $min) = (0, 0, undef); | |
for my $score ($tmp->lines) { | |
$score += 0; | |
$sum += $score; | |
$min //= $score; | |
$min = $score if $min > $score; | |
$max = $score if $max < $score; | |
} | |
printf "Measured %d times\n", $opt{count}; | |
print "\n"; | |
printf "Total Average: %.6f msec\n", $sum / $opt{count}; | |
printf "Total Max: %.6f msec\n", $max; | |
printf "Total Min: %.6f msec\n", $min; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment