Skip to content

Instantly share code, notes, and snippets.

@sys9kdr
Created September 11, 2024 03:22
Show Gist options
  • Save sys9kdr/e3724a3f1710404c0e22f215b4e4bb52 to your computer and use it in GitHub Desktop.
Save sys9kdr/e3724a3f1710404c0e22f215b4e4bb52 to your computer and use it in GitHub Desktop.
-- 測定回数
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
-- vim.fn.has('mac') を使用した macOS 検出
local function detect_with_fn_has()
return vim.fn.has('mac') == 1
end
-- vim.uv を使用した macOS 検出
local function detect_with_uv_os_uname()
return vim.uv.os_uname().sysname == 'Darwin'
end
-- vim.fn.has('mac') の実行時間を測定
local fn_has_time = measure_time(detect_with_fn_has)
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(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