initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / js1_5 / Array / regress-101964.js
1 /*
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is mozilla.org code.
13 *
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation.  Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation.
17 * All Rights Reserved.
18 *
19 * Contributor(s): pschwartau@netscape.com
20 * Date: 27 September 2001
21 *
22 * SUMMARY: Performance: truncating even very large arrays should be fast!
23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=101964
24 *
25 * Adjust this testcase if necessary. The FAST constant defines
26 * an upper bound in milliseconds for any truncation to take.
27 */
28 //-----------------------------------------------------------------------------
29 var UBound = 0;
30 var bug = 101964;
31 var summary = 'Performance: truncating even very large arrays should be fast!';
32 var BIG = 10000000;
33 var LITTLE = 10;
34 var FAST = 50; // array truncation should be 50 ms or less to pass the test
35 var MSG_FAST = 'Truncation took less than ' + FAST + ' ms';
36 var MSG_SLOW = 'Truncation took ';
37 var MSG_MS = ' ms';
38 var status = '';
39 var statusitems = [];
40 var actual = '';
41 var actualvalues = [];
42 var expect= '';
43 var expectedvalues = [];
44
45
46
47 status = inSection(1);
48 var arr = Array(BIG);
49 var start = new Date();
50 arr.length = LITTLE;
51 actual = elapsedTime(start);
52 expect = FAST;
53 addThis();
54
55
56
57 //-----------------------------------------------------------------------------
58 test();
59 //-----------------------------------------------------------------------------
60
61
62
63 function elapsedTime(startTime)
64 {
65   return new Date() - startTime;
66 }
67
68
69 function addThis()
70 {
71   statusitems[UBound] = status;
72   actualvalues[UBound] = isThisFast(actual);
73   expectedvalues[UBound] = isThisFast(expect);
74   UBound++;
75 }
76
77
78 function isThisFast(ms)
79 {
80   if (ms <= FAST)
81     return MSG_FAST;
82   return MSG_SLOW + ms + MSG_MS;
83 }
84
85
86 function test()
87 {
88   enterFunc ('test');
89   printBugNumber (bug);
90   printStatus (summary);
91
92   for (var i=0; i<UBound; i++)
93   {
94     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
95   }
96
97   exitFunc ('test');
98 }