<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./index.js"></script>
</head>
<body>
</body>
</html>
/** 用wasm获取c++写的fib函数 */
const loadWebAssembly = (fileName) => {
return fetch(fileName)
.then((response) => response.arrayBuffer())
.then((buffer) => WebAssembly.compile(buffer))
.then((module) => {
return new WebAssembly.Instance(module);
});
};
loadWebAssembly("./test.wasm").then((instance) => {
fibc = instance.exports._Z3fibi;
});
/** 用js写fib函数 */
const fibj = (n) => {
if (n <= 1) {
return n;
}
return fibj(n - 1) + fibj(n - 2);
};
/** 测试时间 */
const perfoc = (n) => {
const startTime = performance.now();
fibc(n);
const endTime = performance.now();
console.log("c++ fib function time", endTime - startTime, "ms");
return "====================";
};
const perfoj = (n) => {
const startTime = performance.now();
fibj(n);
const endTime = performance.now();
console.log("js fib function time:", endTime - startTime, "ms");
return "====================";
};
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!