Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit.js

Issue 2775713002: Optimize the speed of array iteration in Audit (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 /** 6 /**
7 * @fileOverview WebAudio layout test utility library. Built around W3C's 7 * @fileOverview WebAudio layout test utility library. Built around W3C's
8 * testharness.js. Includes asynchronous test task manager, 8 * testharness.js. Includes asynchronous test task manager,
9 * assertion utilities. 9 * assertion utilities.
10 * @dependency testharness.js 10 * @dependency testharness.js
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 * "PASS [1,1,1] contains only the constant 1." 559 * "PASS [1,1,1] contains only the constant 1."
560 */ 560 */
561 beConstantValueOf () { 561 beConstantValueOf () {
562 this._processArguments(arguments); 562 this._processArguments(arguments);
563 this._printActualForFailure = false; 563 this._printActualForFailure = false;
564 564
565 let passed = true; 565 let passed = true;
566 let passDetail, failDetail; 566 let passDetail, failDetail;
567 let errors = {}; 567 let errors = {};
568 568
569 for (let index in this._actual) { 569 let actual = this._actual;
570 if (this._actual[index] !== this._expected) 570 let expected = this._expected;
571 errors[index] = this._actual[index]; 571 for (let index = 0; index < actual.length; ++index) {
572 if (actual[index] !== expected)
573 errors[index] = actual[index];
572 } 574 }
573 575
574 let numberOfErrors = Object.keys(errors).length; 576 let numberOfErrors = Object.keys(errors).length;
575 passed = numberOfErrors === 0; 577 passed = numberOfErrors === 0;
576 578
577 if (passed) { 579 if (passed) {
578 passDetail = '${actual} contains only the constant ${expected}.'; 580 passDetail = '${actual} contains only the constant ${expected}.';
579 } else { 581 } else {
580 let counter = 0; 582 let counter = 0;
581 failDetail = 'Expected ${expected} for all values but found ' 583 failDetail = 'Expected ${expected} for all values but found '
(...skipping 27 matching lines...) Expand all
609 */ 611 */
610 notBeConstantValueOf () { 612 notBeConstantValueOf () {
611 this._processArguments(arguments); 613 this._processArguments(arguments);
612 this._printActualForFailure = false; 614 this._printActualForFailure = false;
613 615
614 let passed = true; 616 let passed = true;
615 let passDetail; 617 let passDetail;
616 let failDetail; 618 let failDetail;
617 let differences = {}; 619 let differences = {};
618 620
619 for (let index in this._actual) { 621 let actual = this._actual;
620 if (this._actual[index] !== this._expected) 622 let expected = this._expected;
621 differences[index] = this._actual[index]; 623 for (let index = 0; index < actual.length; ++index) {
624 if (actual[index] !== expected)
625 differences[index] = actual[index];
622 } 626 }
623 627
624 let numberOfDifferences = Object.keys(differences).length; 628 let numberOfDifferences = Object.keys(differences).length;
625 passed = numberOfDifferences > 0; 629 passed = numberOfDifferences > 0;
626 630
627 if (passed) { 631 if (passed) {
628 let valueString = numberOfDifferences > 1 ? 'values' : 'value'; 632 let valueString = numberOfDifferences > 1 ? 'values' : 'value';
629 passDetail = '${actual} is not constantly ${expected} (contains ' + 633 passDetail = '${actual} is not constantly ${expected} (contains ' +
630 numberOfDifferences + ' different ' + valueString + ').'; 634 numberOfDifferences + ' different ' + valueString + ').';
631 } else { 635 } else {
(...skipping 20 matching lines...) Expand all
652 let passed = true; 656 let passed = true;
653 let passDetail, failDetail; 657 let passDetail, failDetail;
654 let errorIndices = []; 658 let errorIndices = [];
655 659
656 if (this._actual.length !== this._expected.length) { 660 if (this._actual.length !== this._expected.length) {
657 passed = false; 661 passed = false;
658 failDetail = 'The array length does not match.'; 662 failDetail = 'The array length does not match.';
659 return this._assert(passed, passDetail, failDetail); 663 return this._assert(passed, passDetail, failDetail);
660 } 664 }
661 665
662 for (let index in this._actual) { 666 let actual = this._actual;
663 if (this._actual[index] !== this._expected[index]) 667 let expected = this._expected;
668 for (let index = 0; index < actual.length; ++index) {
669 if (actual[index] !== expected[index])
664 errorIndices.push(index); 670 errorIndices.push(index);
665 } 671 }
666 672
667 passed = errorIndices.length === 0; 673 passed = errorIndices.length === 0;
668 674
669 if (passed) { 675 if (passed) {
670 passDetail = '${actual} is identical to the array ${expected}.'; 676 passDetail = '${actual} is identical to the array ${expected}.';
671 } else { 677 } else {
672 let counter = 0; 678 let counter = 0;
673 failDetail = '${actual} expected to be equal to the array ${expected} ' 679 failDetail = '${actual} expected to be equal to the array ${expected} '
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 * of 0.06." 754 * of 0.06."
749 * 755 *
750 */ 756 */
751 notGlitch () { 757 notGlitch () {
752 this._processArguments(arguments); 758 this._processArguments(arguments);
753 this._printActualForFailure = false; 759 this._printActualForFailure = false;
754 760
755 let passed = true; 761 let passed = true;
756 let passDetail, failDetail; 762 let passDetail, failDetail;
757 763
758 for (let index in this._actual) { 764 let actual = this._actual;
759 let diff = Math.abs(this._actual[index - 1] - this._actual[index]); 765 let expected = this._expected;
760 if (diff >= this._expected) { 766 for (let index = 0; index < actual.length; ++index) {
767 let diff = Math.abs(actual[index - 1] - actual[index]);
768 if (diff >= expected) {
761 passed = false; 769 passed = false;
762 failDetail = '${actual} has a glitch at index ' + index + ' of size ' 770 failDetail = '${actual} has a glitch at index ' + index + ' of size '
763 + diff + '.'; 771 + diff + '.';
764 } 772 }
765 } 773 }
766 774
767 passDetail = 775 passDetail =
768 '${actual} has no glitch above the threshold of ${expected}.'; 776 '${actual} has no glitch above the threshold of ${expected}.';
769 777
770 return this._assert(passed, passDetail, failDetail); 778 return this._assert(passed, passDetail, failDetail);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // expected element. 839 // expected element.
832 let errors = {}; 840 let errors = {};
833 841
834 // Keep track of the max absolute error found. 842 // Keep track of the max absolute error found.
835 let maxAbsError = -Infinity, maxAbsErrorIndex = -1; 843 let maxAbsError = -Infinity, maxAbsErrorIndex = -1;
836 844
837 // Keep track of the max relative error found, ignoring cases where the 845 // Keep track of the max relative error found, ignoring cases where the
838 // relative error is Infinity because the expected value is 0. 846 // relative error is Infinity because the expected value is 0.
839 let maxRelError = -Infinity, maxRelErrorIndex = -1; 847 let maxRelError = -Infinity, maxRelErrorIndex = -1;
840 848
841 for (let index in this._expected) { 849 let actual = this._actual;
842 let diff = Math.abs(this._actual[index] - this._expected[index]); 850 let expected = this._expected;
843 let absExpected = Math.abs(this._expected[index]); 851
852 for (let index = 0; index < expected.length; ++index) {
853 let diff = Math.abs(actual[index] - expected[index]);
854 let absExpected = Math.abs(expected[index]);
844 let relError = diff / absExpected; 855 let relError = diff / absExpected;
845 856
846 if (diff > Math.max(absErrorThreshold, 857 if (diff > Math.max(absErrorThreshold,
847 relErrorThreshold * absExpected)) { 858 relErrorThreshold * absExpected)) {
848 859
849 if (diff > maxAbsError) { 860 if (diff > maxAbsError) {
850 maxAbsErrorIndex = index; 861 maxAbsErrorIndex = index;
851 maxAbsError = diff; 862 maxAbsError = diff;
852 } 863 }
853 864
(...skipping 22 matching lines...) Expand all
876 failDetail = '${actual} does not equal ${expected} with an ' 887 failDetail = '${actual} does not equal ${expected} with an '
877 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n'; 888 + 'element-wise tolerance of ' + maxAllowedErrorDetail + '.\n';
878 889
879 // Print out actual, expected, absolute error, and relative error. 890 // Print out actual, expected, absolute error, and relative error.
880 let counter = 0; 891 let counter = 0;
881 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError' 892 failDetail += '\tIndex\tActual\t\t\tExpected\t\tAbsError'
882 + '\t\tRelError\t\tTest threshold'; 893 + '\t\tRelError\t\tTest threshold';
883 let printedIndices = []; 894 let printedIndices = [];
884 for (let index in errors) { 895 for (let index in errors) {
885 failDetail += '\n' + _formatFailureEntry( 896 failDetail += '\n' + _formatFailureEntry(
886 index, this._actual[index], 897 index, actual[index],
887 this._expected[index], errors[index], 898 expected[index], errors[index],
888 _closeToThreshold( 899 _closeToThreshold(
889 absErrorThreshold, relErrorThreshold, 900 absErrorThreshold, relErrorThreshold,
890 this._expected[index])); 901 expected[index]));
891 902
892 printedIndices.push(index); 903 printedIndices.push(index);
893 if (++counter > this._options.numberOfErrors) { 904 if (++counter > this._options.numberOfErrors) {
894 failDetail += 905 failDetail +=
895 '\n\t...and ' + (numberOfErrors - counter) + ' more errors.'; 906 '\n\t...and ' + (numberOfErrors - counter) + ' more errors.';
896 break; 907 break;
897 } 908 }
898 } 909 }
899 910
900 // Finalize the error log: print out the location of both the maxAbs 911 // Finalize the error log: print out the location of both the maxAbs
901 // error and the maxRel error so we can adjust thresholds appropriately 912 // error and the maxRel error so we can adjust thresholds appropriately
902 // in the test. 913 // in the test.
903 failDetail += '\n' 914 failDetail += '\n'
904 + '\tMax AbsError of ' + maxAbsError.toExponential(16) 915 + '\tMax AbsError of ' + maxAbsError.toExponential(16)
905 + ' at index of ' + maxAbsErrorIndex + '.\n'; 916 + ' at index of ' + maxAbsErrorIndex + '.\n';
906 if (printedIndices.find(element => { 917 if (printedIndices.find(element => {
907 return element == maxAbsErrorIndex; 918 return element == maxAbsErrorIndex;
908 }) === undefined) { 919 }) === undefined) {
909 // Print an entry for this index if we haven't already. 920 // Print an entry for this index if we haven't already.
910 failDetail += 921 failDetail +=
911 _formatFailureEntry( 922 _formatFailureEntry(
912 maxAbsErrorIndex, this._actual[maxAbsErrorIndex], 923 maxAbsErrorIndex, actual[maxAbsErrorIndex],
913 this._expected[maxAbsErrorIndex], errors[maxAbsErrorIndex], 924 expected[maxAbsErrorIndex], errors[maxAbsErrorIndex],
914 _closeToThreshold( 925 _closeToThreshold(
915 absErrorThreshold, relErrorThreshold, 926 absErrorThreshold, relErrorThreshold,
916 this._expected[maxAbsErrorIndex])) + 927 expected[maxAbsErrorIndex])) +
917 '\n'; 928 '\n';
918 } 929 }
919 failDetail += '\tMax RelError of ' + maxRelError.toExponential(16) + 930 failDetail += '\tMax RelError of ' + maxRelError.toExponential(16) +
920 ' at index of ' + maxRelErrorIndex + '.\n'; 931 ' at index of ' + maxRelErrorIndex + '.\n';
921 if (printedIndices.find(element => { 932 if (printedIndices.find(element => {
922 return element == maxRelErrorIndex; 933 return element == maxRelErrorIndex;
923 }) === undefined) { 934 }) === undefined) {
924 // Print an entry for this index if we haven't already. 935 // Print an entry for this index if we haven't already.
925 failDetail += 936 failDetail +=
926 _formatFailureEntry( 937 _formatFailureEntry(
927 maxRelErrorIndex, this._actual[maxRelErrorIndex], 938 maxRelErrorIndex, actual[maxRelErrorIndex],
928 this._expected[maxRelErrorIndex], errors[maxRelErrorIndex], 939 expected[maxRelErrorIndex], errors[maxRelErrorIndex],
929 _closeToThreshold( 940 _closeToThreshold(
930 absErrorThreshold, relErrorThreshold, 941 absErrorThreshold, relErrorThreshold,
931 this._expected[maxRelErrorIndex])) + 942 expected[maxRelErrorIndex])) +
932 '\n'; 943 '\n';
933 } 944 }
934 } 945 }
935 946
936 return this._assert(passed, passDetail, failDetail); 947 return this._assert(passed, passDetail, failDetail);
937 } 948 }
938 949
939 /** 950 /**
940 * A temporary escape hat for printing an in-task message. The description 951 * A temporary escape hat for printing an in-task message. The description
941 * for the |actual| is required to get the message printed properly. 952 * for the |actual| is required to get the message printed properly.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 1269
1259 /** 1270 /**
1260 * Load file from a given URL and pass ArrayBuffer to the following promise. 1271 * Load file from a given URL and pass ArrayBuffer to the following promise.
1261 * See |loadFileFromUrl| method for the detail. 1272 * See |loadFileFromUrl| method for the detail.
1262 */ 1273 */
1263 loadFileFromUrl: loadFileFromUrl 1274 loadFileFromUrl: loadFileFromUrl
1264 1275
1265 }; 1276 };
1266 1277
1267 })(); 1278 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698