Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
Tags (14)
master
2019年12月21日
20200412
20200316
20200119
20200105
20191221
20191027
20190918
20190901
20190818
20190810
20190728
20190721
init
master
Branches (1)
Tags (14)
master
2019年12月21日
20200412
20200316
20200119
20200105
20191221
20191027
20190918
20190901
20190818
20190810
20190728
20190721
init
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
Tags (14)
master
2019年12月21日
20200412
20200316
20200119
20200105
20191221
20191027
20190918
20190901
20190818
20190810
20190728
20190721
init
QuickJS
/
tests
/
microbench.js
QuickJS
/
tests
/
microbench.js
microbench.js 22.48 KB
Copy Edit Raw Blame History
Horunabu Hofutenho authored 2020年03月18日 00:37 +08:00 . 2020年03月16日
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
/*
* Javascript Micro benchmark
*
* Copyright (c) 2017-2019 Fabrice Bellard
* Copyright (c) 2017-2019 Charlie Gordon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import * as std from "std";
function pad(str, n) {
str += "";
while (str.length < n)
str += "";
return str;
}
function pad_left(str, n) {
str += "";
while (str.length < n)
str = "" + str;
return str;
}
function pad_center(str, n) {
str += "";
while (str.length < n) {
if ((n - str.length) & 1)
str = str + "";
else
str = "" + str;
}
return str;
}
function toPrec(n, prec) {
var i, s;
for (i = 0; i < prec; i++)
n *= 10;
s = "" + Math.round(n);
for (i = s.length - prec; i <= 0; i++)
s = "0" + s;
if (prec > 0)
s = s.substring(0, i) + "." + s.substring(i);
return s;
}
var ref_data;
var log_data;
var heads = [ "TEST", "N", "TIME (ns)", "REF (ns)", "SCORE (%)" ];
var widths = [ 22, 10, 9, 9, 9 ];
var precs = [ 0, 0, 2, 2, 2 ];
var total = [ 0, 0, 0, 0, 0 ];
var total_score = 0;
var total_scale = 0;
if (typeof console == "undefined") {
var console = { log: print };
}
function log_line() {
var i, n, s, a;
s = "";
for (i = 0, n = arguments.length; i < n; i++) {
if (i > 0)
s += "";
a = arguments[i];
if (typeof a == "number") {
total[i] += a;
a = toPrec(a, precs[i]);
s += pad_left(a, widths[i]);
} else {
s += pad_left(a, widths[i]);
}
}
console.log(s);
}
var clocks_per_sec = 1000000;
var max_iterations = 100;
var clock_threshold = 2000; /* favoring short measuring spans */
var min_n_argument = 1;
var get_clock;
if (typeof globalThis.__date_clock != "function") {
console.log("using fallback millisecond clock");
clocks_per_sec = 1000;
max_iterations = 10;
clock_threshold = 100;
get_clock = Date.now;
} else {
get_clock = globalThis.__date_clock;
}
function log_one(text, n, ti) {
var ref;
if (ref_data)
ref = ref_data[text];
else
ref = null;
ti = Math.round(ti * 100) / 100;
log_data[text] = ti;
if (typeof ref === "number") {
log_line(text, n, ti, ref, ti * 100 / ref);
total_score += ti * 100 / ref;
total_scale += 100;
} else {
log_line(text, n, ti);
total_score += 100;
total_scale += 100;
}
}
function bench(f, text)
{
var i, j, n, t, t1, ti, nb_its, ref, ti_n, ti_n1, min_ti;
nb_its = n = 1;
if (f.bench) {
ti_n = f(text);
} else {
ti_n = 1000000000;
min_ti = clock_threshold / 10;
for(i = 0; i < 30; i++) {
ti = 1000000000;
for (j = 0; j < max_iterations; j++) {
t = get_clock();
while ((t1 = get_clock()) == t)
continue;
nb_its = f(n);
if (nb_its < 0)
return; // test failure
t1 = get_clock() - t1;
if (ti > t1)
ti = t1;
}
if (ti >= min_ti) {
ti_n1 = ti / nb_its;
if (ti_n > ti_n1)
ti_n = ti_n1;
}
if (ti >= clock_threshold && n >= min_n_argument)
break;
n = n * [ 2, 2.5, 2 ][i % 3];
}
// to use only the best timing from the last loop, uncomment below
//ti_n = ti / nb_its;
}
/* nano seconds per iteration */
log_one(text, n, ti_n * 1e9 / clocks_per_sec);
}
var global_res; /* to be sure the code is not optimized */
function empty_loop(n) {
var j;
for(j = 0; j < n; j++) {
}
return n;
}
function date_now(n) {
var j;
for(j = 0; j < n; j++) {
Date.now();
}
return n;
}
function prop_read(n)
{
var obj, sum, j;
obj = {a: 1, b: 2, c:3, d:4 };
sum = 0;
for(j = 0; j < n; j++) {
sum += obj.a;
sum += obj.b;
sum += obj.c;
sum += obj.d;
}
global_res = sum;
return n * 4;
}
function prop_write(n)
{
var obj, j;
obj = {a: 1, b: 2, c:3, d:4 };
for(j = 0; j < n; j++) {
obj.a = j;
obj.b = j;
obj.c = j;
obj.d = j;
}
return n * 4;
}
function prop_create(n)
{
var obj, j;
for(j = 0; j < n; j++) {
obj = new Object();
obj.a = 1;
obj.b = 2;
obj.c = 3;
obj.d = 4;
}
return n * 4;
}
function array_read(n)
{
var tab, len, sum, i, j;
tab = [];
len = 10;
for(i = 0; i < len; i++)
tab[i] = i;
sum = 0;
for(j = 0; j < n; j++) {
sum += tab[0];
sum += tab[1];
sum += tab[2];
sum += tab[3];
sum += tab[4];
sum += tab[5];
sum += tab[6];
sum += tab[7];
sum += tab[8];
sum += tab[9];
}
global_res = sum;
return len * n;
}
function array_write(n)
{
var tab, len, i, j;
tab = [];
len = 10;
for(i = 0; i < len; i++)
tab[i] = i;
for(j = 0; j < n; j++) {
tab[0] = j;
tab[1] = j;
tab[2] = j;
tab[3] = j;
tab[4] = j;
tab[5] = j;
tab[6] = j;
tab[7] = j;
tab[8] = j;
tab[9] = j;
}
return len * n;
}
function array_prop_create(n)
{
var tab, i, j, len;
len = 1000;
for(j = 0; j < n; j++) {
tab = [];
for(i = 0; i < len; i++)
tab[i] = i;
}
return len * n;
}
function array_length_decr(n)
{
var tab, i, j, len;
len = 1000;
tab = [];
for(i = 0; i < len; i++)
tab[i] = i;
for(j = 0; j < n; j++) {
for(i = len - 1; i >= 0; i--)
tab.length = i;
}
return len * n;
}
function array_hole_length_decr(n)
{
var tab, i, j, len;
len = 1000;
tab = [];
for(i = 0; i < len; i++) {
if (i != 3)
tab[i] = i;
}
for(j = 0; j < n; j++) {
for(i = len - 1; i >= 0; i--)
tab.length = i;
}
return len * n;
}
function array_push(n)
{
var tab, i, j, len;
len = 500;
for(j = 0; j < n; j++) {
tab = [];
for(i = 0; i < len; i++)
tab.push(i);
}
return len * n;
}
function array_pop(n)
{
var tab, i, j, len, sum;
len = 500;
for(j = 0; j < n; j++) {
tab = [];
for(i = 0; i < len; i++)
tab[i] = i;
sum = 0;
for(i = 0; i < len; i++)
sum += tab.pop();
global_res = sum;
}
return len * n;
}
function typed_array_read(n)
{
var tab, len, sum, i, j;
len = 10;
tab = new Int32Array(len);
for(i = 0; i < len; i++)
tab[i] = i;
sum = 0;
for(j = 0; j < n; j++) {
sum += tab[0];
sum += tab[1];
sum += tab[2];
sum += tab[3];
sum += tab[4];
sum += tab[5];
sum += tab[6];
sum += tab[7];
sum += tab[8];
sum += tab[9];
}
global_res = sum;
return len * n;
}
function typed_array_write(n)
{
var tab, len, i, j;
len = 10;
tab = new Int32Array(len);
for(i = 0; i < len; i++)
tab[i] = i;
for(j = 0; j < n; j++) {
tab[0] = j;
tab[1] = j;
tab[2] = j;
tab[3] = j;
tab[4] = j;
tab[5] = j;
tab[6] = j;
tab[7] = j;
tab[8] = j;
tab[9] = j;
}
return len * n;
}
var global_var0;
function global_read(n)
{
var sum, j;
global_var0 = 0;
sum = 0;
for(j = 0; j < n; j++) {
sum += global_var0;
sum += global_var0;
sum += global_var0;
sum += global_var0;
}
global_res = sum;
return n * 4;
}
var global_write =
(1, eval)(`(function global_write(n)
{
var j;
for(j = 0; j < n; j++) {
global_var0 = j;
global_var0 = j;
global_var0 = j;
global_var0 = j;
}
return n * 4;
})`);
function global_write_strict(n)
{
var j;
for(j = 0; j < n; j++) {
global_var0 = j;
global_var0 = j;
global_var0 = j;
global_var0 = j;
}
return n * 4;
}
function local_destruct(n)
{
var j, v1, v2, v3, v4;
var array = [ 1, 2, 3, 4, 5];
var o = { a:1, b:2, c:3, d:4 };
var a, b, c, d;
for(j = 0; j < n; j++) {
[ v1, v2,, v3, ...v4] = array;
({ a, b, c, d } = o);
({ a: a, b: b, c: c, d: d } = o);
}
return n * 12;
}
var global_v1, global_v2, global_v3, global_v4;
var global_a, global_b, global_c, global_d;
var global_destruct =
(1, eval)(`(function global_destruct(n)
{
var j, v1, v2, v3, v4;
var array = [ 1, 2, 3, 4, 5 ];
var o = { a:1, b:2, c:3, d:4 };
var a, b, c, d;
for(j = 0; j < n; j++) {
[ global_v1, global_v2,, global_v3, ...global_v4] = array;
({ a: global_a, b: global_b, c: global_c, d: global_d } = o);
}
return n * 8;
})`);
function global_destruct_strict(n)
{
var j, v1, v2, v3, v4;
var array = [ 1, 2, 3, 4, 5 ];
var o = { a:1, b:2, c:3, d:4 };
var a, b, c, d;
for(j = 0; j < n; j++) {
[ global_v1, global_v2,, global_v3, ...global_v4] = array;
({ a: global_a, b: global_b, c: global_c, d: global_d } = o);
}
return n * 8;
}
function func_call(n)
{
function f(a)
{
return 1;
}
var j, sum;
sum = 0;
for(j = 0; j < n; j++) {
sum += f(j);
sum += f(j);
sum += f(j);
sum += f(j);
}
global_res = sum;
return n * 4;
}
function closure_var(n)
{
function f(a)
{
sum++;
}
var j, sum;
sum = 0;
for(j = 0; j < n; j++) {
f(j);
f(j);
f(j);
f(j);
}
global_res = sum;
return n * 4;
}
function int_arith(n)
{
var i, j, sum;
global_res = 0;
for(j = 0; j < n; j++) {
sum = 0;
for(i = 0; i < 1000; i++) {
sum += i * i;
}
global_res += sum;
}
return n * 1000;
}
function float_arith(n)
{
var i, j, sum, a, incr, a0;
global_res = 0;
a0 = 0.1;
incr = 1.1;
for(j = 0; j < n; j++) {
sum = 0;
a = a0;
for(i = 0; i < 1000; i++) {
sum += a * a;
a += incr;
}
global_res += sum;
}
return n * 1000;
}
function bigfloat_arith(n)
{
var i, j, sum, a, incr, a0;
global_res = 0;
a0 = BigFloat("0.1");
incr = BigFloat("1.1");
for(j = 0; j < n; j++) {
sum = 0;
a = a0;
for(i = 0; i < 1000; i++) {
sum += a * a;
a += incr;
}
global_res += sum;
}
return n * 1000;
}
function float256_arith(n)
{
return BigFloatEnv.setPrec(bigfloat_arith.bind(null, n), 237, 19);
}
function bigint_arith(n, bits)
{
var i, j, sum, a, incr, a0, sum0;
sum0 = global_res = BigInt(0);
a0 = BigInt(1) << BigInt(Math.floor((bits - 10) * 0.5));
incr = BigInt(1);
for(j = 0; j < n; j++) {
sum = sum0;
a = a0;
for(i = 0; i < 1000; i++) {
sum += a * a;
a += incr;
}
global_res += sum;
}
return n * 1000;
}
function bigint64_arith(n)
{
return bigint_arith(n, 64);
}
function bigint256_arith(n)
{
return bigint_arith(n, 256);
}
function set_collection_add(n)
{
var s, i, j, len = 100;
s = new Set();
for(j = 0; j < n; j++) {
for(i = 0; i < len; i++) {
s.add(String(i), i);
}
for(i = 0; i < len; i++) {
if (!s.has(String(i)))
throw Error("bug in Set");
}
}
return n * len;
}
function array_for(n)
{
var r, i, j, sum;
r = [];
for(i = 0; i < 100; i++)
r[i] = i;
for(j = 0; j < n; j++) {
sum = 0;
for(i = 0; i < 100; i++) {
sum += r[i];
}
global_res = sum;
}
return n * 100;
}
function array_for_in(n)
{
var r, i, j, sum;
r = [];
for(i = 0; i < 100; i++)
r[i] = i;
for(j = 0; j < n; j++) {
sum = 0;
for(i in r) {
sum += r[i];
}
global_res = sum;
}
return n * 100;
}
function array_for_of(n)
{
var r, i, j, sum;
r = [];
for(i = 0; i < 100; i++)
r[i] = i;
for(j = 0; j < n; j++) {
sum = 0;
for(i of r) {
sum += i;
}
global_res = sum;
}
return n * 100;
}
function math_min(n)
{
var i, j, r;
r = 0;
for(j = 0; j < n; j++) {
for(i = 0; i < 1000; i++)
r = Math.min(i, 500);
global_res = r;
}
return n * 1000;
}
/* incremental string contruction as local var */
function string_build1(n)
{
var i, j, r;
r = "";
for(j = 0; j < n; j++) {
for(i = 0; i < 100; i++)
r += "x";
global_res = r;
}
return n * 100;
}
/* incremental string contruction as arg */
function string_build2(n, r)
{
var i, j;
r = "";
for(j = 0; j < n; j++) {
for(i = 0; i < 100; i++)
r += "x";
global_res = r;
}
return n * 100;
}
/* incremental string contruction by prepending */
function string_build3(n, r)
{
var i, j;
r = "";
for(j = 0; j < n; j++) {
for(i = 0; i < 100; i++)
r = "x" + r;
global_res = r;
}
return n * 100;
}
/* incremental string contruction with multiple reference */
function string_build4(n)
{
var i, j, r, s;
r = "";
for(j = 0; j < n; j++) {
for(i = 0; i < 100; i++) {
s = r;
r += "x";
}
global_res = r;
}
return n * 100;
}
/* sort bench */
function sort_bench(text) {
function random(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[(Math.random() * n) >> 0];
}
function random8(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[(Math.random() * 256) >> 0];
}
function random1(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[(Math.random() * 2) >> 0];
}
function hill(arr, n, def) {
var mid = n >> 1;
for (var i = 0; i < mid; i++)
arr[i] = def[i];
for (var i = mid; i < n; i++)
arr[i] = def[n - i];
}
function comb(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[(i & 1) * i];
}
function crisscross(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[(i & 1) ? n - i : i];
}
function zero(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[0];
}
function increasing(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[i];
}
function decreasing(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[n - 1 - i];
}
function alternate(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[i ^ 1];
}
function jigsaw(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[i % (n >> 4)];
}
function incbutone(arr, n, def) {
for (var i = 0; i < n; i++)
arr[i] = def[i];
if (n > 0)
arr[n >> 2] = def[n];
}
function incbutfirst(arr, n, def) {
if (n > 0)
arr[0] = def[n];
for (var i = 1; i < n; i++)
arr[i] = def[i];
}
function incbutlast(arr, n, def) {
for (var i = 0; i < n - 1; i++)
arr[i] = def[i + 1];
if (n > 0)
arr[n - 1] = def[0];
}
var sort_cases = [ random, random8, random1, jigsaw, hill, comb,
crisscross, zero, increasing, decreasing, alternate,
incbutone, incbutlast, incbutfirst ];
var n = sort_bench.array_size || 10000;
var array_type = sort_bench.array_type || Array;
var def, arr;
var i, j, x, y;
var total = 0;
var save_total_score = total_score;
var save_total_scale = total_scale;
// initialize default sorted array (n + 1 elements)
def = new array_type(n + 1);
if (array_type == Array) {
for (i = 0; i <= n; i++) {
def[i] = i + "";
}
} else {
for (i = 0; i <= n; i++) {
def[i] = i;
}
}
def.sort();
for (var f of sort_cases) {
var ti = 0, tx = 0;
for (j = 0; j < 100; j++) {
arr = new array_type(n);
f(arr, n, def);
var t1 = get_clock();
arr.sort();
t1 = get_clock() - t1;
tx += t1;
if (!ti || ti > t1)
ti = t1;
if (tx >= clocks_per_sec)
break;
}
total += ti;
i = 0;
x = arr[0];
if (x !== void 0) {
for (i = 1; i < n; i++) {
y = arr[i];
if (y === void 0)
break;
if (x > y)
break;
x = y;
}
}
while (i < n && arr[i] === void 0)
i++;
if (i < n) {
console.log("sort_bench: out of order error for " + f.name +
" at offset " + (i - 1) +
": " + arr[i - 1] + " > " + arr[i]);
}
if (sort_bench.verbose)
log_one("sort_" + f.name, n, ti, n * 100);
}
total_score = save_total_score;
total_scale = save_total_scale;
return total / n / 1000;
}
sort_bench.bench = true;
sort_bench.verbose = false;
function int_to_string(n)
{
var s, r, j;
r = 0;
for(j = 0; j < n; j++) {
s = (j + 1).toString();
}
return n;
}
function float_to_string(n)
{
var s, r, j;
r = 0;
for(j = 0; j < n; j++) {
s = (j + 0.1).toString();
}
return n;
}
function string_to_int(n)
{
var s, r, j;
r = 0;
s = "12345";
r = 0;
for(j = 0; j < n; j++) {
r += (s | 0);
}
global_res = r;
return n;
}
function string_to_float(n)
{
var s, r, j;
r = 0;
s = "12345.6";
r = 0;
for(j = 0; j < n; j++) {
r -= s;
}
global_res = r;
return n;
}
function load_result(filename)
{
var f, str, res;
if (typeof std === "undefined")
return null;
f = std.open(filename, "r");
if (!f)
return null;
str = f.readAsString();
res = JSON.parse(str);
f.close();
return res;
}
function save_result(filename, obj)
{
var f;
if (typeof std === "undefined")
return;
f = std.open(filename, "w");
f.puts(JSON.stringify(obj, null, 2));
f.puts("\n");
f.close();
}
function main(argc, argv, g)
{
var test_list = [
empty_loop,
date_now,
prop_read,
prop_write,
prop_create,
array_read,
array_write,
array_prop_create,
array_length_decr,
array_hole_length_decr,
array_push,
array_pop,
typed_array_read,
typed_array_write,
global_read,
global_write,
global_write_strict,
local_destruct,
global_destruct,
global_destruct_strict,
func_call,
closure_var,
int_arith,
float_arith,
set_collection_add,
array_for,
array_for_in,
array_for_of,
math_min,
string_build1,
string_build2,
//string_build3,
//string_build4,
sort_bench,
int_to_string,
float_to_string,
string_to_int,
string_to_float,
];
var tests = [];
var i, j, n, f, name;
if (typeof BigInt == "function") {
/* BigInt test */
test_list.push(bigint64_arith);
test_list.push(bigint256_arith);
}
if (typeof BigFloat == "function") {
/* BigFloat test */
test_list.push(float256_arith);
}
for (i = 1; i < argc;) {
name = argv[i++];
if (name == "-a") {
sort_bench.verbose = true;
continue;
}
if (name == "-t") {
name = argv[i++];
sort_bench.array_type = g[name];
if (typeof sort_bench.array_type != "function") {
console.log("unknown array type: " + name);
return 1;
}
continue;
}
if (name == "-n") {
sort_bench.array_size = +argv[i++];
continue;
}
for (j = 0; j < test_list.length; j++) {
f = test_list[j];
if (name === f.name) {
tests.push(f);
break;
}
}
if (j == test_list.length) {
console.log("unknown benchmark: " + name);
return 1;
}
}
if (tests.length == 0)
tests = test_list;
ref_data = load_result("microbench.txt");
log_data = {};
log_line.apply(null, heads);
n = 0;
for(i = 0; i < tests.length; i++) {
f = tests[i];
bench(f, f.name, ref_data, log_data);
if (ref_data && ref_data[f.name])
n++;
}
if (ref_data)
log_line("total", "", total[2], total[3], total_score * 100 / total_scale);
else
log_line("total", "", total[2]);
if (tests == test_list)
save_result("microbench-new.txt", log_data);
}
if (!scriptArgs)
scriptArgs = [];
main(scriptArgs.length, scriptArgs, this);
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

QuickJS 是一个轻量且可嵌入的 JavaScript 引擎,它支持 ES2019 规范,包括 ES module、异步生成器以及 proxies
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/smallcodes/QuickJS.git
git@gitee.com:smallcodes/QuickJS.git
smallcodes
QuickJS
QuickJS
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /