Created
November 6, 2019 12:46
-
-
Save pocke/4b164decc432461098bf2bf9807c4009 to your computer and use it in GitHub Desktop.
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
require 'pathname' | |
require 'fileutils' | |
LOG_PATH = Pathname('/tmp/vimbench.log') | |
RE = /(\d+\.\d+)\s*\d+\.\d+:\s*--- N?VIM STARTED ---/ | |
N = 10 | |
def prepare | |
FileUtils.rm LOG_PATH if LOG_PATH.exist? | |
FileUtils.touch LOG_PATH | |
q = Queue.new | |
th = Thread.new do | |
IO.popen('tail -f /tmp/vimbench.log') do |io| | |
io.each_line do |line| | |
q << Object.new if line =~ RE | |
end | |
end | |
end | |
return q, th | |
end | |
def clear(q, th) | |
q.close | |
th.kill | |
end | |
def stats | |
content = LOG_PATH.read | |
content.scan(RE).flatten.map(&:to_f) | |
end | |
def format(stats) | |
<<~END | |
results: #{stats.join ' '} | |
average: #{stats.sum / stats.size} | |
END | |
end | |
q, th = prepare | |
N.times do | |
pid = spawn("vim --startuptime #{LOG_PATH}") | |
q.pop | |
Process.kill :SIGTERM, pid | |
end | |
clear q, th | |
vimrc_stat = stats | |
q, th = prepare | |
# default | |
N.times do | |
pid = spawn("vim -u DEFAULTS --startuptime #{LOG_PATH}") | |
q.pop | |
Process.kill :SIGTERM, pid | |
end | |
clear q, th | |
no_vimrc_stat = stats | |
system 'reset' | |
puts <<~END | |
with vimrc | |
#{format vimrc_stat} | |
no vimrc | |
#{format no_vimrc_stat} | |
#{sprintf("%.3f", vimrc_stat.sum / no_vimrc_stat.sum)}x slower your Vim than the default. | |
END | |
FileUtils.rm LOG_PATH |
Author
pocke
commented
Nov 6, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment