Last active
November 23, 2024 12:21
-
-
Save sys9kdr/03e0772ac9de8715c701f0a4b7840963 to your computer and use it in GitHub Desktop.
neovimのos特定の速度のベンチ
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
-- 測定回数 | |
local iterations = 100000 | |
-- ヘルパー関数で時間を計測 | |
local function measure_time(fn) | |
local start = vim.uv.hrtime() | |
for _ = 1, iterations do | |
fn() | |
end | |
local duration = vim.uv.hrtime() - start | |
return duration / 1e6 -- ナノ秒をミリ秒に変換 | |
end | |
local function detect_with_fn_has() | |
return vim.fn.has('Linux') == 1 | |
end | |
-- vim.uv を使用した macOS 検出 | |
local function detect_with_uv_os_uname() | |
return vim.uv.os_uname().sysname == 'Linux' | |
end | |
-- vim.fn.has('mac') の実行時間を測定 | |
--local fn_has_time = measure_time(detect_with_fn_has) | |
local fn_has_time = measure_time(detect_with_fn_has) | |
print(detect_with_uv_os_uname()) | |
print(string.format("vim.fn.has('mac'): %.2f ms", fn_has_time)) | |
-- vim.uv を使用した実行時間を測定 | |
local uv_time = measure_time(detect_with_uv_os_uname) | |
print(detect_with_uv_os_uname()) | |
print(string.format('vim.uv.os_uname: %.2f ms', uv_time)) | |
-- 結果を比較 | |
if fn_has_time < uv_time then | |
print("vim.fn.has('mac') is faster.") | |
else | |
print('vim.uv.os_uname is faster.') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vim.fn.has
is faster thanvim.uv.os_uname
in neovim v 0.11