Last active
January 30, 2025 13:21
-
-
Save amekusa/84377fd689c7c6cd05dc26074b5666a5 to your computer and use it in GitHub Desktop.
Lua: External Command Overheads Comparison
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
| -- git clone https://github.com/amekusa/humb.lua.git humb | |
| local humb = require('humb') | |
| local test = humb:new_test({ | |
| rpt = 1000, | |
| digits = 4, | |
| }) | |
| do | |
| local os_execute = os.execute | |
| local os_execute_arg = 'echo xxx' | |
| test:case('os.execute', function() | |
| os_execute(os_execute_arg) | |
| end) | |
| end | |
| do | |
| local fn_system = vim.fn.system | |
| local fn_system_arg = 'echo xxx' | |
| test:case('vim.fn.system', function() | |
| fn_system(fn_system_arg) | |
| end) | |
| end | |
| do | |
| local system = vim.system | |
| local system_arg = {'echo', 'xxx'} | |
| test:case('vim.system', function() | |
| system(system_arg):wait() | |
| end) | |
| end | |
| test:run() | |
| test:print() | |
| ---- RESULTS ---- | |
| -- Repeats: 1000 | |
| -- #1: os.execute | |
| -- Elapsed: 0.7508 | |
| -- Average: 0.0008 | |
| -- #2: vim.fn.system | |
| -- Elapsed: 1.1293 | |
| -- Average: 0.0011 | |
| -- #3: vim.system | |
| -- Elapsed: 1.0697 | |
| -- Average: 0.0011 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Conclusion
os.execute()is the fastest.vim.system()is slightly faster thanvim.fn.system().