18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* The contents of this file are subject to the Netscape Public 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* License Version 1.1 (the "License"); you may not use this file 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* except in compliance with the License. You may obtain a copy of 58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* the License at http://www.mozilla.org/NPL/ 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Software distributed under the License is distributed on an "AS 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* implied. See the License for the specific language governing 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* rights and limitations under the License. 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* The Original Code is mozilla.org code. 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* The Initial Developer of the Original Code is Netscape 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Communications Corporation. Portions created by Netscape are 168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Copyright (C) 1998 Netscape Communications Corporation. 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* All Rights Reserved. 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Contributor(s): pschwartau@netscape.com 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Date: 27 September 2001 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* SUMMARY: Performance: truncating even very large arrays should be fast! 238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* See http://bugzilla.mozilla.org/show_bug.cgi?id=101964 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* Adjust this testcase if necessary. The FAST constant defines 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project* an upper bound in milliseconds for any truncation to take. 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project*/ 288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project//----------------------------------------------------------------------------- 298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar UBound = 0; 308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar bug = 101964; 318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar summary = 'Performance: truncating even very large arrays should be fast!'; 328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar BIG = 10000000; 338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar LITTLE = 10; 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar FAST = 50; // array truncation should be 50 ms or less to pass the test 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar MSG_FAST = 'Truncation took less than ' + FAST + ' ms'; 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar MSG_SLOW = 'Truncation took '; 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar MSG_MS = ' ms'; 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar status = ''; 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar statusitems = []; 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar actual = ''; 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar actualvalues = []; 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar expect= ''; 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar expectedvalues = []; 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstatus = inSection(1); 488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar arr = Array(BIG); 498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvar start = new Date(); 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectarr.length = LITTLE; 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectactual = elapsedTime(start); 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectexpect = FAST; 538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectaddThis(); 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project//----------------------------------------------------------------------------- 588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projecttest(); 598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project//----------------------------------------------------------------------------- 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction elapsedTime(startTime) 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return new Date() - startTime; 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction addThis() 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project statusitems[UBound] = status; 728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project actualvalues[UBound] = isThisFast(actual); 738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project expectedvalues[UBound] = isThisFast(expect); 748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project UBound++; 758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction isThisFast(ms) 798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (ms <= FAST) 818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return MSG_FAST; 828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return MSG_SLOW + ms + MSG_MS; 838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectfunction test() 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project enterFunc ('test'); 898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project printBugNumber (bug); 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project printStatus (summary); 918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project for (var i=0; i<UBound; i++) 938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project { 948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project exitFunc ('test'); 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 99