Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@icyflame
Created October 1, 2019 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icyflame/5809a23c0e391943be7451daaf61f1c9 to your computer and use it in GitHub Desktop.
Save icyflame/5809a23c0e391943be7451daaf61f1c9 to your computer and use it in GitHub Desktop.
Find whether multiple export statements, a single export statement or no export statement contributes to the fastest shell loading time

TL; DR

Option Time taken to source zshrc
No Imports 1152ms
Import in a single line 1158ms
Import in multiple export statements 1169ms

Options

Option 1: No Imports

# export PATH="$PATH:$HOME/bin:$HOME/bin/tsv-utils:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

# export PATH="$PATH:/usr/local/sbin"
# export PATH="$PATH:/usr/local/bin"
# export PATH="$PATH:/usr/sbin"
# export PATH="$PATH:/usr/bin"
# export PATH="$PATH:/sbin"
# export PATH="$PATH:/bin"
# export PATH="$PATH:/usr/games"

Option 2: Multiple Import Line

export PATH="$PATH:/usr/local/sbin"
export PATH="$PATH:/usr/local/bin"
export PATH="$PATH:/usr/sbin"
export PATH="$PATH:/usr/bin"
export PATH="$PATH:/sbin"
export PATH="$PATH:/bin"
export PATH="$PATH:/usr/games"

Option 3: Single Import Line

export PATH="$PATH:$HOME/bin:$HOME/bin/tsv-utils:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

Sourcing the zshrc ~10 times and recording the time taken

$ node -p -e 'new Date() - 0'; source ~/.zshrc; node -p -e 'new Date() - 0';

Open a new tmux pane and just run this command ten times. When done, copy the output of all ten commands to a text file and print the differences as an array using this:

$ cat no_imports_benchmarks.txt | paste - - | gawk '{ print $2-$1 }' | paste -s -d',' -

Calculating the average times

> without_path_imports = [993,999,1026,1055,1093,1120,1201,1205,1225,1247,1283,1384
... ]
[
   993,  999, 1026,
  1055, 1093, 1120,
  1201, 1205, 1225,
  1247, 1283, 1384
]
> _.mean(without_path_imports)
1152.5833333333333
> single_path_import = [1034,1006,1040,1071,1199,1140,1163,1202,1290,1287,1315
... ]
[
  1034, 1006, 1040,
  1071, 1199, 1140,
  1163, 1202, 1290,
  1287, 1315
]
> _.mean(single_path_import)
1158.8181818181818
> multiple_path_imports = [985,1014,1040,1079,1119,1133,1227,1205,1252,1282,1342,1357
... ]
[
   985, 1014, 1040,
  1079, 1119, 1133,
  1227, 1205, 1252,
  1282, 1342, 1357
]
> _.mean(multiple_path_imports)
1169.5833333333333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment