html 是否有类型数组,有或没有分配大小#jsbench #jsperf(http://jsbench.github.io/#3127ca10954b5121df21352e9baf8d05)#js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 是否有类型数组,有或没有分配大小#jsbench #jsperf(http://jsbench.github.io/#3127ca10954b5121df21352e9baf8d05)#js相关的知识,希望对你有一定的参考价值。

"use strict";

(function (factory) {
	if (typeof Benchmark !== "undefined") {
		factory(Benchmark);
	} else {
		factory(require("benchmark"));
	}
})(function (Benchmark) {
	var suite = new Benchmark.Suite;



	suite.add("if (!window.xA) {window.xA = []}", function () {
		if (!window.xA) {window.xA = []}
		var x = xA
		var i = 0
		for (i = 0; i<255; i++){
		    x[i] = i
		}
		for (i; i<510; i++){
		    x[i] = i - 255
		}
		var result
		for (i = 0; i<255; i++){
		    result = x[i]
		}
	});

	suite.add("if (!window.x8_65536) {window.x8_65536 = new Uint8Array(65536)}", function () {
		if (!window.x8_65536) {window.x8_65536 = new Uint8Array(65536)}
		var x = x8_65536
		var i = 0
		for (i = 0; i<255; i++){
		    x[i] = i
		}
		for (i; i<510; i++){
		    x[i] = i - 255
		}
		var result
		for (i = 0; i<255; i++){
		    result = x[i]
		}
	});

	suite.add("if (!window.x8_1024) {window.x8_1024 = new Uint8Array(1024)}", function () {
		if (!window.x8_1024) {window.x8_1024 = new Uint8Array(1024)}
		var x = x8_1024
		var i = 0
		for (i = 0; i<255; i++){
		    x[i] = i
		}
		for (i; i<510; i++){
		    x[i] = i - 255
		}
		var result
		for (i = 0; i<255; i++){
		    result = x[i]
		}
	});

	suite.add("if (!window.x8) {window.x8 = new Uint8Array()}", function () {
		if (!window.x8) {window.x8 = new Uint8Array()}
		var x = x8
		var i = 0
		for (i = 0; i<255; i++){
		    x[i] = i
		}
		for (i; i<510; i++){
		    x[i] = i - 255
		}
		var result
		for (i = 0; i<255; i++){
		    result = x[i]
		}
	});

	suite.on("cycle", function (evt) {
		console.log(" - " + evt.target);
	});

	suite.on("complete", function (evt) {
		console.log(new Array(30).join("-"));

		var results = evt.currentTarget.sort(function (a, b) {
			return b.hz - a.hz;
		});

		results.forEach(function (item) {
			console.log((idx + 1) + ". " + item);
		});
	});

	console.log("typed array or not, with or without allocating size #jsbench #jsperf");
	console.log(new Array(30).join("-"));
	suite.run();
});
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<title>typed array or not, with or without allocating size #jsbench #jsperf</title>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
	<script src="./suite.js"></script>
</head>
<body>
	<h1>Open the console to view the results</h1>
	<h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2>
</body>
</html>

以上是关于html 是否有类型数组,有或没有分配大小#jsbench #jsperf(http://jsbench.github.io/#3127ca10954b5121df21352e9baf8d05)#js的主要内容,如果未能解决你的问题,请参考以下文章

如何根据鼠标移动在 html 页面顶部绘制图像的一部分? (有或没有画布)

是否可以在 Rust 运行时确定大小的堆栈分配数组?

Location.getTime 返回 UTC 有或没有闰秒?

sizeof和strlen的区别

new与malloc的区别struct与class的区别

new与malloc的区别struct与class的区别