LoginSignup
17
19

More than 5 years have passed since last update.

zshフレームワークの起動速度&設定の楽さ比較!

Last updated at Posted at 2019-01-03

以前はfishシェルを使っていましたが、bashとの互換の無さが気になりzshに移行することにしました。
ただしzshはfishのように最初から使いやすく設定されていないのでフレームワークを選定する必要がありました。
以下zsh主要フレームワークを起動スピード&設定の楽さで比較した結果です。

比較対象のフレームワーク一覧

比較条件

・環境はUbuntu Desktop 18.04にて比較。
・fishから移行するので、fishに最低限近づけるためのプラグインとテーマを入れ設定の楽さと起動スピードを比較。

下記のプラグインを導入し比較

各種設定

oh-my-zsh

.zshrcを編集したり、git cloneで各種プラグインをダウンロードしてくる必要がある。

プラグインのインストール

$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
$ git clone https://github.com/zsh-users/zsh-completions ~/.oh-my-zsh/custom/plugins/zsh-completions
$ git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search

プラグインとテーマの設定
vim ~/.zshrc

# Pureテーマ
ZSH_THEME="refined"
# プラグインを有効化
plugins=(zsh-autosuggestions zsh-syntax-highlighting zsh-completions history-substring-search)
autoload -U compinit && compinit

Prezto

最初からモジュールが用意されているため、それを利用し設定を行う
基本的にPreztoの設定は~/.zpreztorcにて行う
他の自分用の設定は~/.zshrcで行う

vim ~/.zpreztorc

# Pureテーマ
zstyle ':prezto:module:prompt' theme 'pure'

# 各種モジュールをロード
zstyle ':prezto:load' pmodule \
  'environment' \
  'terminal' \
  'editor' \
  'history' \
  'directory' \
  'spectrum' \
  'utility' \
  'completion' \
  'syntax-highlighting' \
  'history-substring-search' \
  'autosuggestions' \
  'prompt'

promptの前に

  'syntax-highlighting' \
  'history-substring-search' \
  'autosuggestions' \

を追加しこれでプラグインのインストールは完了
※ 最初から設定されているモジュールがありますが、デフォルトで設定されているのでこのまま比較

zplug

~/.zshrcの1ファイルでプラグイン管理と自分の設定を管理する

vim ~/.zshrc

source ~/.zplug/init.zsh

# Pure theme
zplug mafredri/zsh-async, from:github
zplug sindresorhus/pure, use:pure.zsh, from:github, as:theme

# Plugins
zplug "zsh-users/zsh-autosuggestions"
zplug "zsh-users/zsh-completions"
zplug "zsh-users/zsh-syntax-highlighting"
zplug "zsh-users/zsh-history-substring-search"

# Install plugins if there are plugins that have not been installed
if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    fi
fi

# Then, source plugins and add commands to $PATH
zplug load

必要最低限の設定にしました

速度比較結果

multitimeコマンドを利用してzshのインタラクティブシェルの起動をしてから終了までの速度を測定しました。
$ multitime -n 15 zsh -i -c exit(15回繰り返し平均を測る)
なおzplugだけは何故かmultitimeコマンドが使えなかったため、timeコマンドを使用しました。
$ time ( zsh -i -c exit )

  • 生zsh
            Mean        Std.Dev.    Min         Median      Max
real        0.031       0.002       0.026       0.032       0.035       
user        0.021       0.005       0.013       0.021       0.028       
sys         0.011       0.005       0.004       0.011       0.019
  • oh-my-zsh
            Mean        Std.Dev.    Min         Median      Max
real        0.134       0.011       0.120       0.131       0.164       
user        0.091       0.012       0.069       0.091       0.119       
sys         0.046       0.010       0.032       0.044       0.067
  • Prezto
            Mean        Std.Dev.    Min         Median      Max
real        0.082       0.006       0.073       0.083       0.091       
user        0.053       0.011       0.034       0.051       0.072       
sys         0.030       0.008       0.018       0.028       0.045 
  • zplug
0.14s user 0.09s system 112% cpu 0.203 total
  • ちなみにfishは
            Mean        Std.Dev.    Min         Median      Max
real        0.010       0.002       0.007       0.010       0.013       
user        0.006       0.003       0.000       0.007       0.010       
sys         0.003       0.004       0.000       0.003       0.012

ということで速い順でPrezto(0.082秒)>oh-my-zsh(0.134秒)>zplug(0.203秒)という結果になりました。

結論

  • oh-my-zshはプラグインごとにgit cloneをしたり設定が非常に面倒
  • zplugは設定がとてもしやすいが非常に起動が遅い

ので自分はこれらは選ばないことにしました。

ということで設定がしやすい起動も速いPreztoが総合的に優れているという結論に達しました。
fishから乗り換えを考えている人はぜひPreztoフレームワークを使ってみてください!

17
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
19