lua - 为什么相同的代码在 lua 中比在 julia 中慢?
问题描述
当我写出相同的代码来找到一个数字的最小倍数时,Julia 比 Lua 快得多,分别需要 ~3 秒和 ~23 秒。
这是我的 Julia 代码:
function smallest_multiple(x)
n = 1
while true
for i = 1:x
if n % i != 0
break
elseif i == x
return n
end
end
n += 1
end
end
println(smallest_multiple(20))
这是 Lua 代码:
function Smallest_Multiple(x)
local n = 1
while true do
for i = 1,x do
if n % i ~= 0 then
break
elseif i == x then
return n
end
end
n = n + 1
end
end
语言之间是否存在根本的低级差异或代码中的疏忽?
解决方案
推荐阅读
- reactjs - 尝试创建反应应用程序时出现错误
- node.js - updating relative schema in mongodb using nodejs
- c# - 在 Hololens 上访问 Unityplayer.log 时遇到问题
- python - 如何从网页中提取数据并将其转换为正确的 Pandas 数据框?
- python-3.x - 如何将excel中的列转换为python中的列表
- google-colaboratory - 无法在 google colab pro 帐户中切换到 HIGH RAM。请告诉我如何切换到高 RAM
- vue.js - 在 vue3 中调用函数后运行计算
- r - R、rvest、文本抓取 - 根据标签从 HTML 节点中删除特定元素
- java - JPype 从 JAR 文件中导入外部库
- firebase - 我可以使用电话号码而不是电子邮件在 Firebase 中设置无密码身份验证吗?