How to use benchmarkBlock method in Best

Best JavaScript code snippet using best

benchmark.js

Source:benchmark.js Github

copy

Full Screen

...30}31const DEFAULT_MAXSIZE = 100000000032const DEFAULT_TARGETTIME = 2533const SAMPLE_SIZE = 3034function benchmarkBlock(name, unrolledOps, func) {35 var MAXSIZE = DEFAULT_MAXSIZE || 100000000;36 var TARGETTIME = DEFAULT_TARGETTIME || 1000;37 unrolledOps = unrolledOps || 1;38 var time = 0.0;39 var size = 100; 40 var ops = 0;41 var obj = new BenchClass();42 // warmup43 func(100, obj);44 // find good size45 while(time < TARGETTIME && size < MAXSIZE) {46 // console.log("execute func: " + time + " " + size)47 func(1, obj);48 var time1 = new Date().getTime();49 func(size, obj);50 var time2 = new Date().getTime();51 time = time2 - time1;52 ops = (unrolledOps * size);53 size *= 2;54 };55 // measure56 let sample = new Array(SAMPLE_SIZE);57 for (let i = 0; i < SAMPLE_SIZE; i++) {58 let time1 = new Date().getTime();59 func(size, obj);60 let time2 = new Date().getTime();61 let timedelta = time2 - time1;62 sample[i] = ops / timedelta;63 }64 // var result = extendString(name, 40) + ralign(String(ops), 16) + " " +65 // ralign(String(time), 4) + " " + ralign(String(Math.round(ops / time)), 8);66 let result = [name, size, ops].concat(sample).join();67 console.log(result);68}69export function benchmark(work) {70 // warmup71 const startTime = Date.now();72 for (let i = 0; i < 50 || Date.now() - startTime < 800; i++) {73 work();74 }75 // measure76 let sample = new Array(SAMPLE_SIZE);77 for (let i = 0; i < SAMPLE_SIZE; i++) {78 const start = Date.now();79 work();80 const end = Date.now();81 sample[i] = end - start;82 }83 return sample;84}85/*86 * Benchmark subjects87 */88const L1 = new Layer("L1");89const L2 = new Layer("L2");90const L3 = new Layer("L3");91const L4 = new Layer("L4");92const L5 = new Layer("L5");93const L6 = new Layer("L6");94const L7 = new Layer("L7");95const L8 = new Layer("L8");96const L9 = new Layer("L9");97const L10 = new Layer("L10");98/**99 * Benchmark subject with counter variables from 00 to 10.100 * They can be increased with noLayer_##(), and countWithoutLayers without COP101 * and with countWithLayers with COP.102 */103class BenchClass {104 constructor() {105 this.counter_00= 0;106 this.counter_01= 0;107 this.counter_02= 0;108 this.counter_03= 0;109 this.counter_04= 0;110 this.counter_05= 0;111 this.counter_06= 0;112 this.counter_07= 0;113 this.counter_08= 0;114 this.counter_09= 0;115 this.counter_10= 0;116 }117 /**118 * Increases all the counters from 01 up to the number of this method.119 * No conditionals are involved, only which method is called determines120 * which counters are affected.121 * This also applies to all other noLayer_## methods.122 */123 noLayer_01() { 124 this.counter_01++;125 }126 noLayer_02() { 127 this.counter_01++; this.counter_02++;128 }129 noLayer_03() { 130 this.counter_01++; this.counter_02++; this.counter_03++;131 }132 noLayer_04() { 133 this.counter_01++; this.counter_02++; this.counter_03++; this.counter_04++;134 }135 noLayer_05() { 136 this.counter_01++; this.counter_02++; this.counter_03++; this.counter_04++; this.counter_05++;137 }138 noLayer_06() { 139 this.counter_01++; this.counter_02++; this.counter_03++; this.counter_04++; this.counter_05++; this.counter_06++;140 }141 noLayer_07() { 142 this.counter_01++; this.counter_02++; this.counter_03++; this.counter_04++; this.counter_05++; this.counter_06++; this.counter_07++;143 }144 noLayer_08(){ 145 this.counter_01++; this.counter_02++; this.counter_03++; this.counter_04++; this.counter_05++; this.counter_06++; this.counter_07++; this.counter_08++;146 }147 noLayer_09(){ 148 this.counter_01++; this.counter_02++; this.counter_03++; this.counter_04++; this.counter_05++; this.counter_06++; this.counter_07++; this.counter_08++; this.counter_09++;149 }150 noLayer_10(){ 151 this.counter_01++; this.counter_02++; this.counter_03++; this.counter_04++; this.counter_05++; this.counter_06++; 152 this.counter_07++; this.counter_08++; this.counter_09++; this.counter_10++;153 }154 /**155 * Increases counters depending on the supplied context object.156 * For each truthy valued property layerX (1 <= X <= 10)157 * the respective counter will be updated.158 */159 countWithoutLayers(context){160 if(context.layer1) { 161 this.counter_01++; 162 };163 if(context.layer2) { 164 this.counter_02++; 165 };166 if(context.layer3) {167 this.counter_03++; 168 };169 if(context.layer4) {170 this.counter_04++; 171 };172 if(context.layer5) {173 this.counter_05++; 174 };175 if(context.layer6) {176 this.counter_06++;177 };178 if(context.layer7) { 179 this.counter_07++; 180 };181 if(context.layer8) {182 this.counter_08++; 183 };184 if(context.layer9) {185 this.counter_09++; 186 };187 if(context.layer10) {188 this.counter_10++;189 };190 }191 /**192 * Increases counters based on the currently active COP layers.193 */194 countWithLayers() { 195 this.counter_00++;196 }197}198L1.refineClass(BenchClass, {199 countWithLayers() { 200 this.counter_01++;201 cop.proceed()202 }203})204 205L2.refineClass(BenchClass, {206 countWithLayers() { 207 this.counter_02++;208 cop.proceed()209 }210})211 212L3.refineClass(BenchClass, {213 countWithLayers() { 214 this.counter_03++;215 cop.proceed()216 }217})218 219L4.refineClass(BenchClass, {220 countWithLayers() { 221 this.counter_04++;222 cop.proceed()223 }224})225 226L5.refineClass(BenchClass, {227 countWithLayers() { 228 this.counter_05++;229 cop.proceed()230 }231})232 233L6.refineClass(BenchClass, {234 countWithLayers() { 235 this.counter_06++;236 cop.proceed()237 }238})239 240L7.refineClass(BenchClass, {241 countWithLayers() { 242 this.counter_07++;243 cop.proceed()244 }245})246 247L8.refineClass(BenchClass, {248 countWithLayers() { 249 this.counter_08++;250 cop.proceed()251 }252})253L9.refineClass(BenchClass, {254 countWithLayers() { 255 this.counter_09++;256 cop.proceed()257 }258})259L10.refineClass(BenchClass, {260 countWithLayers() { 261 this.counter_10++;262 cop.proceed()263 }264})265/**266 * Benchmark subject with counters from 01 to 05.267 * Each method increases all counters based on the currently active COP layers.268 */269class C1 {270 initialize() {271 this.counter_01= 0;272 this.counter_02= 0;273 this.counter_03= 0;274 this.counter_04= 0;275 this.counter_05= 0;276 }277 278 m1() {this.counter_00++;}279 m2() {this.counter_00++;}280 m3() {this.counter_00++;}281 m4() {this.counter_00++;}282 m5() {this.counter_00++;}283}284L1.refineClass(C1, {285 m1() {this.counter_01++;}, 286 m2() {this.counter_01++;}, 287 m3() {this.counter_01++;}, 288 m4() {this.counter_01++;}, 289 m5() {this.counter_01++;}290})291L2.refineClass(C1, {292 m1() {this.counter_02++;},293 m2() {this.counter_02++;}, 294 m3() {this.counter_02++;}, 295 m4() {this.counter_02++;}, 296 m5() {this.counter_02++;}297})298L3.refineClass(C1, {299 m1() {this.counter_03++;},300 m2() {this.counter_03++;}, 301 m3() {this.counter_03++;}, 302 m4() {this.counter_03++;}, 303 m5() {this.counter_03++;}304})305L4.refineClass(C1, {306 m1() {this.counter_04++;},307 m2() {this.counter_04++;}, 308 m3() {this.counter_04++;}, 309 m4() {this.counter_04++;}, 310 m5() {this.counter_04++;}311})312L5.refineClass(C1, {313 m1() {this.counter_05++;},314 m2() {this.counter_05++;}, 315 m3() {this.counter_05++;}, 316 m4() {this.counter_05++;}, 317 m5() {this.counter_05++;}318})319/*320 * Benchmarks321 */322export function explicitContextBenchmarks() {323 var runWithContext = function(name, context) {324 benchmarkBlock(name, 16, function(size, obj) {325 for(var i = 0; i < size; i++) { 326 obj.countWithoutLayers(context);327 obj.countWithoutLayers(context);328 obj.countWithoutLayers(context);329 obj.countWithoutLayers(context);330 obj.countWithoutLayers(context);331 obj.countWithoutLayers(context);332 obj.countWithoutLayers(context);333 obj.countWithoutLayers(context);334 obj.countWithoutLayers(context);335 obj.countWithoutLayers(context);336 obj.countWithoutLayers(context);337 obj.countWithoutLayers(context);338 obj.countWithoutLayers(context);339 obj.countWithoutLayers(context);340 obj.countWithoutLayers(context);341 obj.countWithoutLayers(context); 342 }343 })344 };345 346 return [347 {name: "ContextJS:Method:Standard:0 ", run: function() {348 runWithContext(this.name, {})349 }},350 {name: "ContextJS:Method:Standard:1 ", run: function() {351 runWithContext(this.name, {layer1: true})352 }},353 {name: "ContextJS:Method:Standard:2 ", run: function() {354 runWithContext(this.name, {layer1: true, layer2: true })355 }},356 {name: "ContextJS:Method:Standard:3 ", run: function() {357 runWithContext(this.name, {layer1: true, layer2: true, layer3: true })358 }},359 {name: "ContextJS:Method:Standard:4 ", run: function() {360 runWithContext(this.name, {layer1: true, layer2: true, layer3: true, layer4: true })361 }},362 {name: "ContextJS:Method:Standard:5 ", run: function() {363 runWithContext(this.name, {layer1: true, layer2: true, layer3: true, layer4: true, layer5: true })364 }},365 {name: "ContextJS:Method:Standard:6 ", run: function() {366 runWithContext(this.name, {layer1: true, layer2: true, layer3: true, layer4: true, layer5: true, layer6: true })367 }},368 {name: "ContextJS:Method:Standard:7 ", run: function() {369 runWithContext(this.name, {layer1: true, layer2: true, layer3: true, layer4: true, layer5: true, layer6: true, layer7: true })370 }},371 {name: "ContextJS:Method:Standard:8 ", run: function() {372 runWithContext(this.name, {layer1: true, layer2: true, layer3: true, layer4: true, layer5: true, layer6: true, layer7: true, layer8: true })373 }},374 {name: "ContextJS:Method:Standard:9 ", run: function() {375 runWithContext(this.name, {layer1: true, layer2: true, layer3: true, layer4: true, layer5: true, layer6: true, layer7: true, layer8: true, layer9: true })376 }},377 {name: "ContextJS:Method:Standard:10 ", run: function() {378 runWithContext(this.name, {layer1: true, layer2: true, layer3: true, layer4: true, layer5: true, layer6: true, layer7: true, layer8: true, layer9: true, layer10: true })379 }}]380}381export function plainCallsBenchmarks() {382 return [383 {name: "ContextJS:Method:NoLayer_01", run: function() {384 benchmarkBlock(this.name, 16, function(size, obj) {385 for(var i = 0; i < size; i++) { 386 obj.noLayer_01(); 387 obj.noLayer_01(); 388 obj.noLayer_01(); 389 obj.noLayer_01(); 390 obj.noLayer_01(); 391 obj.noLayer_01(); 392 obj.noLayer_01(); 393 obj.noLayer_01(); 394 obj.noLayer_01(); 395 obj.noLayer_01(); 396 obj.noLayer_01(); 397 obj.noLayer_01(); 398 obj.noLayer_01(); 399 obj.noLayer_01(); 400 obj.noLayer_01(); 401 obj.noLayer_01(); 402 }})403 } 404 },405 {name: "ContextJS:Method:NoLayer_02", run: function() {406 benchmarkBlock(this.name, 16, function(size, obj) {407 for(var i = 0; i < size; i++) { 408 obj.noLayer_02(); 409 obj.noLayer_02(); 410 obj.noLayer_02(); 411 obj.noLayer_02(); 412 obj.noLayer_02(); 413 obj.noLayer_02(); 414 obj.noLayer_02(); 415 obj.noLayer_02(); 416 obj.noLayer_02(); 417 obj.noLayer_02(); 418 obj.noLayer_02(); 419 obj.noLayer_02(); 420 obj.noLayer_02(); 421 obj.noLayer_02(); 422 obj.noLayer_02(); 423 obj.noLayer_02(); 424 }})425 }426 },427 {name: "ContextJS:Method:NoLayer_03", run: function() {428 benchmarkBlock(this.name, 16, function(size, obj) {429 for(var i = 0; i < size; i++) { 430 obj.noLayer_03(); 431 obj.noLayer_03(); 432 obj.noLayer_03(); 433 obj.noLayer_03(); 434 obj.noLayer_03(); 435 obj.noLayer_03(); 436 obj.noLayer_03(); 437 obj.noLayer_03(); 438 obj.noLayer_03(); 439 obj.noLayer_03(); 440 obj.noLayer_03(); 441 obj.noLayer_03(); 442 obj.noLayer_03(); 443 obj.noLayer_03(); 444 obj.noLayer_03(); 445 obj.noLayer_03(); 446 }})447 }448 },449 {name: "ContextJS:Method:NoLayer_04", run: function() {450 benchmarkBlock(this.name, 16, function(size, obj) {451 for(var i = 0; i < size; i++) { 452 obj.noLayer_04(); 453 obj.noLayer_04(); 454 obj.noLayer_04(); 455 obj.noLayer_04(); 456 obj.noLayer_04(); 457 obj.noLayer_04(); 458 obj.noLayer_04(); 459 obj.noLayer_04(); 460 obj.noLayer_04(); 461 obj.noLayer_04(); 462 obj.noLayer_04(); 463 obj.noLayer_04(); 464 obj.noLayer_04(); 465 obj.noLayer_04(); 466 obj.noLayer_04(); 467 obj.noLayer_04(); 468 }})469 }470 },471 {name: "ContextJS:Method:NoLayer_05", run: function() {472 benchmarkBlock(this.name, 16, function(size, obj) {473 for(var i = 0; i < size; i++) { 474 obj.noLayer_05(); 475 obj.noLayer_05(); 476 obj.noLayer_05(); 477 obj.noLayer_05(); 478 obj.noLayer_05(); 479 obj.noLayer_05(); 480 obj.noLayer_05(); 481 obj.noLayer_05(); 482 obj.noLayer_05(); 483 obj.noLayer_05(); 484 obj.noLayer_05(); 485 obj.noLayer_05(); 486 obj.noLayer_05(); 487 obj.noLayer_05(); 488 obj.noLayer_05(); 489 obj.noLayer_05(); 490 }})491 }492 },493 {name: "ContextJS:Method:NoLayer_06", run: function() {494 benchmarkBlock(this.name, 16, function(size, obj) {495 for(var i = 0; i < size; i++) { 496 obj.noLayer_06(); 497 obj.noLayer_06(); 498 obj.noLayer_06(); 499 obj.noLayer_06(); 500 obj.noLayer_06(); 501 obj.noLayer_06(); 502 obj.noLayer_06(); 503 obj.noLayer_06(); 504 obj.noLayer_06(); 505 obj.noLayer_06(); 506 obj.noLayer_06(); 507 obj.noLayer_06(); 508 obj.noLayer_06(); 509 obj.noLayer_06(); 510 obj.noLayer_06(); 511 obj.noLayer_06(); 512 }})513 }514 },515 {name: "ContextJS:Method:NoLayer_07", run: function() {516 benchmarkBlock(this.name, 16, function(size, obj) {517 for(var i = 0; i < size; i++) { 518 obj.noLayer_07(); 519 obj.noLayer_07(); 520 obj.noLayer_07(); 521 obj.noLayer_07(); 522 obj.noLayer_07(); 523 obj.noLayer_07(); 524 obj.noLayer_07(); 525 obj.noLayer_07(); 526 obj.noLayer_07(); 527 obj.noLayer_07(); 528 obj.noLayer_07(); 529 obj.noLayer_07(); 530 obj.noLayer_07(); 531 obj.noLayer_07(); 532 obj.noLayer_07(); 533 obj.noLayer_07(); 534 }})535 }536 },537 {name: "ContextJS:Method:NoLayer_08", run: function() {538 benchmarkBlock(this.name, 16, function(size, obj) {539 for(var i = 0; i < size; i++) { 540 obj.noLayer_08(); 541 obj.noLayer_08(); 542 obj.noLayer_08(); 543 obj.noLayer_08(); 544 obj.noLayer_08(); 545 obj.noLayer_08(); 546 obj.noLayer_08(); 547 obj.noLayer_08(); 548 obj.noLayer_08(); 549 obj.noLayer_08(); 550 obj.noLayer_08(); 551 obj.noLayer_08(); 552 obj.noLayer_08(); 553 obj.noLayer_08(); 554 obj.noLayer_08(); 555 obj.noLayer_08(); 556 }})557 }558 },559 {name: "ContextJS:Method:NoLayer_09", run: function() {560 benchmarkBlock(this.name, 16, function(size, obj) {561 for(var i = 0; i < size; i++) { 562 obj.noLayer_09(); 563 obj.noLayer_09(); 564 obj.noLayer_09(); 565 obj.noLayer_09(); 566 obj.noLayer_09(); 567 obj.noLayer_09(); 568 obj.noLayer_09(); 569 obj.noLayer_09(); 570 obj.noLayer_09(); 571 obj.noLayer_09(); 572 obj.noLayer_09(); 573 obj.noLayer_09(); 574 obj.noLayer_09(); 575 obj.noLayer_09(); 576 obj.noLayer_09(); 577 obj.noLayer_01(); 578 }})579 }580 },581 {name: "ContextJS:Method:NoLayer_10", run: function() {582 benchmarkBlock(this.name, 16, function(size, obj) {583 for(var i = 0; i < size; i++) { 584 obj.noLayer_10(); 585 obj.noLayer_10(); 586 obj.noLayer_10(); 587 obj.noLayer_10(); 588 obj.noLayer_10(); 589 obj.noLayer_10(); 590 obj.noLayer_10(); 591 obj.noLayer_10(); 592 obj.noLayer_10(); 593 obj.noLayer_10(); 594 obj.noLayer_10(); 595 obj.noLayer_10(); 596 obj.noLayer_10(); 597 obj.noLayer_10(); 598 obj.noLayer_10(); 599 obj.noLayer_10(); 600 }})601 }602 }]603}604export function copContextBenchmarks() {605 return [606 {name: "ContextJS:Method:WithLayer:0 ", run: function() {607 benchmarkBlock(this.name, 16, function(size, obj) {608 for(var i = 0; i < size; i++) { 609 obj.countWithLayers(); 610 obj.countWithLayers(); 611 obj.countWithLayers(); 612 obj.countWithLayers(); 613 obj.countWithLayers(); 614 obj.countWithLayers(); 615 obj.countWithLayers(); 616 obj.countWithLayers(); 617 obj.countWithLayers(); 618 obj.countWithLayers(); 619 obj.countWithLayers(); 620 obj.countWithLayers(); 621 obj.countWithLayers(); 622 obj.countWithLayers(); 623 obj.countWithLayers(); 624 obj.countWithLayers(); 625 }})626 }627 },628 {name: "ContextJS:Method:WithLayer:1 ", run: function() {629 cop.withLayers([L1], () => {630 benchmarkBlock(this.name, 16, function(size, obj) {631 for(var i = 0; i < size; i++) { 632 obj.countWithLayers(); 633 obj.countWithLayers(); 634 obj.countWithLayers(); 635 obj.countWithLayers(); 636 obj.countWithLayers(); 637 obj.countWithLayers(); 638 obj.countWithLayers(); 639 obj.countWithLayers(); 640 obj.countWithLayers(); 641 obj.countWithLayers(); 642 obj.countWithLayers(); 643 obj.countWithLayers(); 644 obj.countWithLayers(); 645 obj.countWithLayers(); 646 obj.countWithLayers(); 647 obj.countWithLayers(); 648 }649 });650 })}651 },652 {name: "ContextJS:Method:WithLayer:2 ", run: function() {653 cop.withLayers([L1, L2], () => {654 benchmarkBlock(this.name, 16, function(size, obj) {655 for(var i = 0; i < size; i++) { 656 obj.countWithLayers(); 657 obj.countWithLayers(); 658 obj.countWithLayers(); 659 obj.countWithLayers(); 660 obj.countWithLayers(); 661 obj.countWithLayers(); 662 obj.countWithLayers(); 663 obj.countWithLayers(); 664 obj.countWithLayers(); 665 obj.countWithLayers(); 666 obj.countWithLayers(); 667 obj.countWithLayers(); 668 obj.countWithLayers(); 669 obj.countWithLayers(); 670 obj.countWithLayers(); 671 obj.countWithLayers(); 672 }673 });674 })}675 },676 {name: "ContextJS:Method:WithLayer:3 ", run: function() {677 cop.withLayers([L1, L2, L3], () => {678 benchmarkBlock(this.name, 16, function(size, obj) {679 for(var i = 0; i < size; i++) { 680 obj.countWithLayers(); 681 obj.countWithLayers(); 682 obj.countWithLayers(); 683 obj.countWithLayers(); 684 obj.countWithLayers(); 685 obj.countWithLayers(); 686 obj.countWithLayers(); 687 obj.countWithLayers(); 688 obj.countWithLayers(); 689 obj.countWithLayers(); 690 obj.countWithLayers(); 691 obj.countWithLayers(); 692 obj.countWithLayers(); 693 obj.countWithLayers(); 694 obj.countWithLayers(); 695 obj.countWithLayers(); 696 }697 });698 })}699 },700 {name: "ContextJS:Method:WithLayer:4 ", run: function() {701 cop.withLayers([L1, L2, L3, L4], () => {702 benchmarkBlock(this.name, 16, function(size, obj) {703 for(var i = 0; i < size; i++) { 704 obj.countWithLayers(); 705 obj.countWithLayers(); 706 obj.countWithLayers(); 707 obj.countWithLayers(); 708 obj.countWithLayers(); 709 obj.countWithLayers(); 710 obj.countWithLayers(); 711 obj.countWithLayers(); 712 obj.countWithLayers(); 713 obj.countWithLayers(); 714 obj.countWithLayers(); 715 obj.countWithLayers(); 716 obj.countWithLayers(); 717 obj.countWithLayers(); 718 obj.countWithLayers(); 719 obj.countWithLayers(); 720 }721 });722 })}723 },724 {name: "ContextJS:Method:WithLayer:5 ", run: function() {725 cop.withLayers([L1, L2, L3, L4, L5], () => {726 benchmarkBlock(this.name, 16, function(size, obj) {727 for(var i = 0; i < size; i++) { 728 obj.countWithLayers(); 729 obj.countWithLayers(); 730 obj.countWithLayers(); 731 obj.countWithLayers(); 732 obj.countWithLayers(); 733 obj.countWithLayers(); 734 obj.countWithLayers(); 735 obj.countWithLayers(); 736 obj.countWithLayers(); 737 obj.countWithLayers(); 738 obj.countWithLayers(); 739 obj.countWithLayers(); 740 obj.countWithLayers(); 741 obj.countWithLayers(); 742 obj.countWithLayers(); 743 obj.countWithLayers(); 744 }745 });746 })}747 },748 {name: "ContextJS:Method:WithLayer:6 ", run: function() {749 cop.withLayers([L1, L2, L3, L4, L5, L6], () => {750 benchmarkBlock(this.name, 16, function(size, obj) {751 for(var i = 0; i < size; i++) { 752 obj.countWithLayers(); 753 obj.countWithLayers(); 754 obj.countWithLayers(); 755 obj.countWithLayers(); 756 obj.countWithLayers(); 757 obj.countWithLayers(); 758 obj.countWithLayers(); 759 obj.countWithLayers(); 760 obj.countWithLayers(); 761 obj.countWithLayers(); 762 obj.countWithLayers(); 763 obj.countWithLayers(); 764 obj.countWithLayers(); 765 obj.countWithLayers(); 766 obj.countWithLayers(); 767 obj.countWithLayers(); 768 }769 });770 })}771 },772 {name: "ContextJS:Method:WithLayer:7 ", run: function() {773 cop.withLayers([L1, L2, L3, L4, L5, L6, L7], () => {774 benchmarkBlock(this.name, 16, function(size, obj) {775 for(var i = 0; i < size; i++) { 776 obj.countWithLayers(); 777 obj.countWithLayers(); 778 obj.countWithLayers(); 779 obj.countWithLayers(); 780 obj.countWithLayers(); 781 obj.countWithLayers(); 782 obj.countWithLayers(); 783 obj.countWithLayers(); 784 obj.countWithLayers(); 785 obj.countWithLayers(); 786 obj.countWithLayers(); 787 obj.countWithLayers(); 788 obj.countWithLayers(); 789 obj.countWithLayers(); 790 obj.countWithLayers(); 791 obj.countWithLayers(); 792 }793 });794 })}795 },796 {name: "ContextJS:Method:WithLayer:8 ", run: function() {797 cop.withLayers([L1, L2, L3, L4, L5, L6, L7, L8], () => {798 benchmarkBlock(this.name, 16, function(size, obj) {799 for(var i = 0; i < size; i++) { 800 obj.countWithLayers(); 801 obj.countWithLayers(); 802 obj.countWithLayers(); 803 obj.countWithLayers(); 804 obj.countWithLayers(); 805 obj.countWithLayers(); 806 obj.countWithLayers(); 807 obj.countWithLayers(); 808 obj.countWithLayers(); 809 obj.countWithLayers(); 810 obj.countWithLayers(); 811 obj.countWithLayers(); 812 obj.countWithLayers(); 813 obj.countWithLayers(); 814 obj.countWithLayers(); 815 obj.countWithLayers(); 816 }817 });818 })}819 },820 {name: "ContextJS:Method:WithLayer:9 ", run: function() {821 cop.withLayers([L1, L2, L3, L4, L5, L6, L7, L8, L9], () => {822 benchmarkBlock(this.name, 16, function(size, obj) {823 for(var i = 0; i < size; i++) { 824 obj.countWithLayers(); 825 obj.countWithLayers(); 826 obj.countWithLayers(); 827 obj.countWithLayers(); 828 obj.countWithLayers(); 829 obj.countWithLayers(); 830 obj.countWithLayers(); 831 obj.countWithLayers(); 832 obj.countWithLayers(); 833 obj.countWithLayers(); 834 obj.countWithLayers(); 835 obj.countWithLayers(); 836 obj.countWithLayers(); 837 obj.countWithLayers(); 838 obj.countWithLayers(); 839 obj.countWithLayers(); 840 }841 });842 })}843 },844 {name: "ContextJS:Method:WithLayer:10 ", run: function() {845 cop.withLayers([L1, L2, L3, L4, L5, L6, L7, L8, L9, L10], () => {846 benchmarkBlock(this.name, 16, function(size, obj) {847 for(var i = 0; i < size; i++) { 848 obj.countWithLayers(); 849 obj.countWithLayers(); 850 obj.countWithLayers(); 851 obj.countWithLayers(); 852 obj.countWithLayers(); 853 obj.countWithLayers(); 854 obj.countWithLayers(); 855 obj.countWithLayers(); 856 obj.countWithLayers(); 857 obj.countWithLayers(); 858 obj.countWithLayers(); 859 obj.countWithLayers(); 860 obj.countWithLayers(); 861 obj.countWithLayers(); 862 obj.countWithLayers(); 863 obj.countWithLayers(); 864 }865 });866 })}867 }] 868}869export function repeatedNestedLayerActivationsBenchmarks() {870 var o1 = new C1();871 return [872 {name: "ContextJS:ActivateLayer:0 ", run: function() {873 benchmarkBlock(this.name, 1, function(size, obj) {874 for(var i = 0; i < size; i++) {875 o1.m1();876 o1.m2();877 o1.m3();878 o1.m4();879 o1.m5();880 }})881 }882 },883 {name: "ContextJS:ActivateLayer:1 ", run: function() {884 benchmarkBlock(this.name, 1, function(size, obj) {885 for(var i = 0; i < size; i++) {886 cop.withLayers([L1], function() {887 o1.m1();888 o1.m2();889 o1.m3();890 o1.m4();891 o1.m5();892 }); 893 }})894 }895 },896 {name: "ContextJS:ActivateLayer:2 ", run: function() {897 benchmarkBlock(this.name, 1, function(size, obj) {898 for(var i = 0; i < size; i++) {899 cop.withLayers([L1], function() {900 o1.m1();901 cop.withLayers([L2], function() {902 o1.m2();903 o1.m3();904 o1.m4();905 o1.m5();906 }); 907 }); 908 }})909 }910 },911 {name: "ContextJS:ActivateLayer:3 ", run: function() {912 benchmarkBlock(this.name, 1, function(size, obj) {913 for(var i = 0; i < size; i++) {914 cop.withLayers([L1], function() {915 o1.m1();916 cop.withLayers([L2], function() {917 o1.m2();918 cop.withLayers([L3], function() {919 o1.m3();920 o1.m4();921 o1.m5();922 });923 }); 924 }); 925 }})926 }927 },928 {name: "ContextJS:ActivateLayer:4 ", run: function() {929 benchmarkBlock(this.name, 1, function(size, obj) {930 for(var i = 0; i < size; i++) {931 cop.withLayers([L1], function() {932 o1.m1();933 cop.withLayers([L2], function() {934 o1.m2();935 cop.withLayers([L3], function() {936 o1.m3();937 cop.withLayers([L4], function() {938 o1.m4();939 o1.m5();940 });941 });942 }); 943 }); 944 }})945 }946 },947 {name: "ContextJS:ActivateLayer:5 ", run: function() {948 benchmarkBlock(this.name, 1, function(size, obj) {949 for(var i = 0; i < size; i++) {950 cop.withLayers([L1], function() {951 o1.m1();952 cop.withLayers([L2], function() {953 o1.m2();954 cop.withLayers([L3], function() {955 o1.m3();956 cop.withLayers([L4], function() {957 o1.m4();958 cop.withLayers([L5], function() {959 o1.m5();960 });961 });962 });963 }); 964 }); 965 }})966 }967 }]968}969export function repeatedLayerActivationsBenchmarks() {970 var o1 = new C1();971 return [972 {name: "ContextJS:ActivateLayerFlat:0 ", run: function() {973 benchmarkBlock(this.name, 1, function(size, obj) {974 for(var i = 0; i < size; i++) {975 o1.m1();976 o1.m2();977 o1.m3();978 o1.m4();979 o1.m5();980 }})981 }982 },983 {name: "ContextJS:ActivateLayerFlat:1 ", run: function() {984 benchmarkBlock(this.name, 1, function(size, obj) {985 for(var i = 0; i < size; i++) {986 cop.withLayers([L1], function() {987 o1.m1();988 o1.m2();989 o1.m3();990 o1.m4();991 o1.m5();992 });993 }})994 }995 },996 {name: "ContextJS:ActivateLayerFlat:2 ", run: function() {997 benchmarkBlock(this.name, 1, function(size, obj) {998 for(var i = 0; i < size; i++) {999 cop.withLayers([L1, L2], function() {1000 o1.m1();1001 o1.m2();1002 o1.m3();1003 o1.m4();1004 o1.m5();1005 });1006 }})1007 }1008 },1009 {name: "ContextJS:ActivateLayerFlat:3 ", run: function() {1010 benchmarkBlock(this.name, 1, function(size, obj) {1011 for(var i = 0; i < size; i++) {1012 cop.withLayers([L1, L2, L3], function() {1013 o1.m1();1014 o1.m2();1015 o1.m3();1016 o1.m4();1017 o1.m5();1018 });1019 }})1020 }1021 },1022 {name: "ContextJS:ActivateLayerFlat:4 ", run: function() {1023 benchmarkBlock(this.name, 1, function(size, obj) {1024 for(var i = 0; i < size; i++) {1025 cop.withLayers([L1, L2, L3, L4], function() {1026 o1.m1();1027 o1.m2();1028 o1.m3();1029 o1.m4();1030 o1.m5();1031 });1032 }})1033 }1034 },1035 {name: "ContextJS:ActivateLayerFlat:5 ", run: function() {1036 benchmarkBlock(this.name, 1, function(size, obj) {1037 for(var i = 0; i < size; i++) {1038 cop.withLayers([L1, L2, L3, L4, L5], function() {1039 o1.m1();1040 o1.m2();1041 o1.m3();1042 o1.m4();1043 o1.m5();1044 });1045 }})1046 }1047 }]1048}1049/**1050 * Benchmark subject for measuring various variants of wrapped methods.1051 */1052class WrapBench {1053 constructor() {1054 this.counter_01 = 0;1055 this.counter_02 = 01056 }1057 1058 m1() {1059 this.counter_01++;1060 }1061}1062export function methodWrappingBenchmarks() {1063 var o1 = new WrapBench(); // unmodified1064 var o2 = new WrapBench();1065 o2.m1 = function() {this.counter_02++;} // plain overwritten1066 // wrap and call original1067 var o3 = new WrapBench();1068 const original_m1 = o3.m1.bind(o3);1069 o3.m1 = function wrappedm1(...args) {1070 original_m1();1071 this.counter_02++;1072 };1073 // put arguments into an array1074 var o4 = new WrapBench();1075 o4.m1 = function(...args) {1076 this.counter_01++; 1077 args.shift();1078 return args1079 };1080 return [1081 {name: "WrapperBenchmark:Default ", run: function() {1082 benchmarkBlock(this.name, 16, function(size, obj) {1083 for(var i = 0; i < size; i++) {1084 o1.m1();1085 o1.m1();1086 o1.m1();1087 o1.m1();1088 o1.m1();1089 o1.m1();1090 o1.m1();1091 o1.m1();1092 o1.m1();1093 o1.m1();1094 o1.m1();1095 o1.m1();1096 o1.m1();1097 o1.m1();1098 o1.m1();1099 o1.m1();1100 }})1101 }1102 },1103 {name: "WrapperBenchmark:InstanceSpecific ", run: function() {1104 benchmarkBlock(this.name, 16, function(size, obj) {1105 for(var i = 0; i < size; i++) {1106 o2.m1();1107 o2.m1(); 1108 o2.m1(); 1109 o2.m1(); 1110 o2.m1(); 1111 o2.m1(); 1112 o2.m1(); 1113 o2.m1(); 1114 o2.m1(); 1115 o2.m1(); 1116 o2.m1(); 1117 o2.m1(); 1118 o2.m1(); 1119 o2.m1(); 1120 o2.m1(); 1121 o2.m1();1122 }})1123 }1124 },1125 {name: "WrapperBenchmark:Wrap", run: function() {1126 benchmarkBlock(this.name, 16, function(size, obj) {1127 for(var i = 0; i < size; i++) {1128 o3.m1();1129 o3.m1();1130 o3.m1();1131 o3.m1();1132 o3.m1();1133 o3.m1();1134 o3.m1();1135 o3.m1();1136 o3.m1();1137 o3.m1();1138 o3.m1();1139 o3.m1();1140 o3.m1();1141 o3.m1();1142 o3.m1();1143 o3.m1();1144 }})1145 }1146 },1147 {name: "WrapperBenchmark:ArgsToArray", run: function() {1148 benchmarkBlock(this.name, 16, function(size, obj) {1149 for(var i = 0; i < size; i++) {1150 o4.m1(1,2,'Hello World');1151 o4.m1(1,2,'Hello World');1152 o4.m1(1,2,'Hello World');1153 o4.m1(1,2,'Hello World');1154 o4.m1(1,2,'Hello World');1155 o4.m1(1,2,'Hello World');1156 o4.m1(1,2,'Hello World');1157 o4.m1(1,2,'Hello World');1158 o4.m1(1,2,'Hello World');1159 o4.m1(1,2,'Hello World');1160 o4.m1(1,2,'Hello World');1161 o4.m1(1,2,'Hello World');1162 o4.m1(1,2,'Hello World');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestTime = require('./bestTime.js');2var bestTime = new BestTime();3var bestTime2 = new BestTime();4var bestTime3 = new BestTime();5var bestTime4 = new BestTime();6var bestTime5 = new BestTime();7var bestTime6 = new BestTime();8var bestTime7 = new BestTime();9var bestTime8 = new BestTime();10var bestTime9 = new BestTime();11var bestTime10 = new BestTime();12var bestTime11 = new BestTime();13var bestTime12 = new BestTime();14var bestTime13 = new BestTime();15var bestTime14 = new BestTime();16var bestTime15 = new BestTime();17var bestTime16 = new BestTime();18var bestTime17 = new BestTime();19var bestTime18 = new BestTime();20var bestTime19 = new BestTime();21var bestTime20 = new BestTime();22var bestTime21 = new BestTime();23var bestTime22 = new BestTime();24var bestTime23 = new BestTime();25var bestTime24 = new BestTime();26var bestTime25 = new BestTime();27var bestTime26 = new BestTime();28var bestTime27 = new BestTime();29var bestTime28 = new BestTime();30var bestTime29 = new BestTime();31var bestTime30 = new BestTime();32var bestTime31 = new BestTime();33var bestTime32 = new BestTime();34var bestTime33 = new BestTime();35var bestTime34 = new BestTime();36var bestTime35 = new BestTime();37var bestTime36 = new BestTime();38var bestTime37 = new BestTime();39var bestTime38 = new BestTime();40var bestTime39 = new BestTime();41var bestTime40 = new BestTime();42var bestTime41 = new BestTime();43var bestTime42 = new BestTime();44var bestTime43 = new BestTime();45var bestTime44 = new BestTime();46var bestTime45 = new BestTime();47var bestTime46 = new BestTime();48var bestTime47 = new BestTime();49var bestTime48 = new BestTime();50var bestTime49 = new BestTime();51var bestTime50 = new BestTime();52var bestTime51 = new BestTime();53var bestTime52 = new BestTime();54var bestTime53 = new BestTime();55var bestTime54 = new BestTime();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestTimeToBuyAndSellStock = require('./BestTimeToBuyAndSellStock.js');2var bestTimeToBuyAndSellStock = new BestTimeToBuyAndSellStock();3var prices = [7,1,5,3,6,4];4console.log("Best time to buy and sell stock");5console.log("prices: " + prices);6console.log("bestTimeToBuyAndSellStock(prices): " + bestTimeToBuyAndSellStock.bestTimeToBuyAndSellStock(prices));7console.log("bestTimeToBuyAndSellStock2(prices): " + bestTimeToBuyAndSellStock.bestTimeToBuyAndSellStock2(prices));8console.log("benchmarking bestTimeToBuyAndSellStock method");9bestTimeToBuyAndSellStock.benchmarkBlock(function(){10 var prices = [7,1,5,3,6,4];11 bestTimeToBuyAndSellStock.bestTimeToBuyAndSellStock(prices);12});13console.log("benchmarking bestTimeToBuyAndSellStock2 method");14bestTimeToBuyAndSellStock.benchmarkBlock(function(){15 var prices = [7,1,5,3,6,4];16 bestTimeToBuyAndSellStock.bestTimeToBuyAndSellStock2(prices);17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPractice = require('./BestPractice.js');2var bp = new BestPractice();3bp.benchmarkBlock(10000000, function() {4 var a = 1;5 var b = 2;6 var c = a + b;7 var d = c * 2;8 var e = d / 2;9 var f = e - 2;10 var g = f % 2;11 var h = g + 2;12 var i = h * 2;13 var j = i / 2;14 var k = j - 2;15 var l = k % 2;16 var m = l + 2;17 var n = m * 2;18 var o = n / 2;19 var p = o - 2;20 var q = p % 2;21 var r = q + 2;22 var s = r * 2;23 var t = s / 2;24 var u = t - 2;25 var v = u % 2;26 var w = v + 2;27 var x = w * 2;28 var y = x / 2;29 var z = y - 2;30 var aa = z % 2;31 var bb = aa + 2;32 var cc = bb * 2;33 var dd = cc / 2;34 var ee = dd - 2;35 var ff = ee % 2;36 var gg = ff + 2;37 var hh = gg * 2;38 var ii = hh / 2;39 var jj = ii - 2;40 var kk = jj % 2;41 var ll = kk + 2;42 var mm = ll * 2;43 var nn = mm / 2;44 var oo = nn - 2;45 var pp = oo % 2;46 var qq = pp + 2;47 var rr = qq * 2;48 var ss = rr / 2;49 var tt = ss - 2;50 var uu = tt % 2;51 var vv = uu + 2;52 var ww = vv * 2;53 var xx = ww / 2;54 var yy = xx - 2;55 var zz = yy % 2;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestTimeToBuyAndSellStock = require('../BestTimeToBuyAndSellStock');2var bestTimeToBuyAndSellStock = new BestTimeToBuyAndSellStock();3var prices = [7, 1, 5, 3, 6, 4];4console.log("Input: [7, 1, 5, 3, 6, 4]");5console.log("Output: " + bestTimeToBuyAndSellStock.maxProfit(prices));6console.log("Time taken to execute the function: " + bestTimeToBuyAndSellStock.benchmarkBlock() + " milliseconds");

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPractice = require('../src/best-practice');2var fs = require('fs');3var bestPractice = new BestPractice();4var testCode = fs.readFileSync('./test/test4.js', 'utf8');5var result = bestPractice.benchmarkBlock(testCode);6console.log('Benchmark result: ', result);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful