Index: test/intl/overrides/caching.js |
diff --git a/test/mjsunit/regress/regress-crbug-178790.js b/test/intl/overrides/caching.js |
similarity index 65% |
copy from test/mjsunit/regress/regress-crbug-178790.js |
copy to test/intl/overrides/caching.js |
index 57071eaa087c3503c4d1ef56e0fd87000a364a29..b15d8d39de2ce30d22fe92f195fe64d21fc91ccc 100644 |
--- a/test/mjsunit/regress/regress-crbug-178790.js |
+++ b/test/intl/overrides/caching.js |
@@ -24,29 +24,38 @@ |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// limitations under the License. |
-// Create a regexp in the form of a?a?...a? so that fully |
-// traversing the entire graph would be prohibitively expensive. |
-// This should not cause time out. |
-var r1 = ""; |
+// Performance test for overriden methods. Makes sure that default case |
+// is faster (cached) than the general case. |
+ |
+// Default, cached. |
+var startTime = new Date(); |
for (var i = 0; i < 1000; i++) { |
- r1 += "a?"; |
+ 'a'.localeCompare('c'); |
} |
-"test".match(RegExp(r1)); |
+var endTime = new Date(); |
+var cachedTime = endTime.getTime() - startTime.getTime(); |
-var r2 = ""; |
-for (var i = 0; i < 100; i++) { |
- r2 += "(a?|b?|c?|d?|e?|f?|g?)"; |
+// Not cached. |
+startTime = new Date(); |
+for (var i = 0; i < 1000; i++) { |
+ 'a'.localeCompare('c', 'sr'); |
} |
-"test".match(RegExp(r2)); |
+endTime = new Date(); |
+var nonCachedTime = endTime.getTime() - startTime.getTime(); |
-// Create a regexp in the form of ((..(a)a..)a. |
-// Compiling it causes EatsAtLeast to reach the maximum |
-// recursion depth possible with a given budget. |
-// This should not cause a stack overflow. |
-var r3 = "a"; |
+// Using collator. Faster than default, but not by much. |
+var collator = Intl.Collator(); |
+startTime = new Date(); |
for (var i = 0; i < 1000; i++) { |
- r3 = "(" + r3 + ")a"; |
+ collator.compare('a', 'c'); |
} |
-"test".match(RegExp(r3)); |
+endTime = new Date(); |
+collatorTime = endTime.getTime() - startTime.getTime(); |
+ |
+// Difference is within 20%. |
+assertTrue(collatorTime < cachedTime); |
+// Non-cached time is much slower, measured to 12.5 times. |
+assertTrue(cachedTime < nonCachedTime); |