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

Side by Side Diff: test/mjsunit/math-min-max.js

Issue 470001: Performance improvement for Math.max and Math.min... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years 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 | Annotate | Revision Log
« no previous file with comments | « src/math.js ('k') | 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 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --allow-natives-syntax
29
28 // Test Math.min(). 30 // Test Math.min().
29 31
30 assertEquals(Number.POSITIVE_INFINITY, Math.min()); 32 assertEquals(Infinity, Math.min());
31 assertEquals(1, Math.min(1)); 33 assertEquals(1, Math.min(1));
32 assertEquals(1, Math.min(1, 2)); 34 assertEquals(1, Math.min(1, 2));
33 assertEquals(1, Math.min(2, 1)); 35 assertEquals(1, Math.min(2, 1));
34 assertEquals(1, Math.min(1, 2, 3)); 36 assertEquals(1, Math.min(1, 2, 3));
35 assertEquals(1, Math.min(3, 2, 1)); 37 assertEquals(1, Math.min(3, 2, 1));
36 assertEquals(1, Math.min(2, 3, 1)); 38 assertEquals(1, Math.min(2, 3, 1));
37 assertEquals(1.1, Math.min(1.1, 2.2, 3.3)); 39 assertEquals(1.1, Math.min(1.1, 2.2, 3.3));
38 assertEquals(1.1, Math.min(3.3, 2.2, 1.1)); 40 assertEquals(1.1, Math.min(3.3, 2.2, 1.1));
39 assertEquals(1.1, Math.min(2.2, 3.3, 1.1)); 41 assertEquals(1.1, Math.min(2.2, 3.3, 1.1));
40 42
43 // Prepare a non-Smi zero value.
44 function returnsNonSmi(){ return 0.25; }
45 var ZERO = returnsNonSmi() - returnsNonSmi();
46 assertEquals(0, ZERO);
47 assertEquals(Infinity, 1/ZERO);
48 assertEquals(-Infinity, 1/-ZERO);
49 assertFalse(%_IsSmi(ZERO));
50 assertFalse(%_IsSmi(-ZERO));
51
41 var o = {}; 52 var o = {};
42 o.valueOf = function() { return 1; }; 53 o.valueOf = function() { return 1; };
43 assertEquals(1, Math.min(2, 3, '1')); 54 assertEquals(1, Math.min(2, 3, '1'));
44 assertEquals(1, Math.min(3, o, 2)); 55 assertEquals(1, Math.min(3, o, 2));
45 assertEquals(1, Math.min(o, 2)); 56 assertEquals(1, Math.min(o, 2));
46 assertEquals(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / Math.min(-0, + 0)); 57 assertEquals(-Infinity, Infinity / Math.min(-0, +0));
47 assertEquals(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / Math.min(+0, - 0)); 58 assertEquals(-Infinity, Infinity / Math.min(+0, -0));
48 assertEquals(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / Math.min(+0, - 0, 1)); 59 assertEquals(-Infinity, Infinity / Math.min(+0, -0, 1));
60 assertEquals(-Infinity, Infinity / Math.min(-0, ZERO));
61 assertEquals(-Infinity, Infinity / Math.min(ZERO, -0));
62 assertEquals(-Infinity, Infinity / Math.min(ZERO, -0, 1));
49 assertEquals(-1, Math.min(+0, -0, -1)); 63 assertEquals(-1, Math.min(+0, -0, -1));
50 assertEquals(-1, Math.min(-1, +0, -0)); 64 assertEquals(-1, Math.min(-1, +0, -0));
51 assertEquals(-1, Math.min(+0, -1, -0)); 65 assertEquals(-1, Math.min(+0, -1, -0));
52 assertEquals(-1, Math.min(-0, -1, +0)); 66 assertEquals(-1, Math.min(-0, -1, +0));
53 assertNaN(Math.min('oxen')); 67 assertNaN(Math.min('oxen'));
54 assertNaN(Math.min('oxen', 1)); 68 assertNaN(Math.min('oxen', 1));
55 assertNaN(Math.min(1, 'oxen')); 69 assertNaN(Math.min(1, 'oxen'));
56 70
57 71
58 // Test Math.max(). 72 // Test Math.max().
59 73
60 assertEquals(Number.NEGATIVE_INFINITY, Math.max()); 74 assertEquals(Number.NEGATIVE_INFINITY, Math.max());
61 assertEquals(1, Math.max(1)); 75 assertEquals(1, Math.max(1));
62 assertEquals(2, Math.max(1, 2)); 76 assertEquals(2, Math.max(1, 2));
63 assertEquals(2, Math.max(2, 1)); 77 assertEquals(2, Math.max(2, 1));
64 assertEquals(3, Math.max(1, 2, 3)); 78 assertEquals(3, Math.max(1, 2, 3));
65 assertEquals(3, Math.max(3, 2, 1)); 79 assertEquals(3, Math.max(3, 2, 1));
66 assertEquals(3, Math.max(2, 3, 1)); 80 assertEquals(3, Math.max(2, 3, 1));
67 assertEquals(3.3, Math.max(1.1, 2.2, 3.3)); 81 assertEquals(3.3, Math.max(1.1, 2.2, 3.3));
68 assertEquals(3.3, Math.max(3.3, 2.2, 1.1)); 82 assertEquals(3.3, Math.max(3.3, 2.2, 1.1));
69 assertEquals(3.3, Math.max(2.2, 3.3, 1.1)); 83 assertEquals(3.3, Math.max(2.2, 3.3, 1.1));
70 84
71 var o = {}; 85 var o = {};
72 o.valueOf = function() { return 3; }; 86 o.valueOf = function() { return 3; };
73 assertEquals(3, Math.max(2, '3', 1)); 87 assertEquals(3, Math.max(2, '3', 1));
74 assertEquals(3, Math.max(1, o, 2)); 88 assertEquals(3, Math.max(1, o, 2));
75 assertEquals(3, Math.max(o, 1)); 89 assertEquals(3, Math.max(o, 1));
76 assertEquals(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Math.max(-0, + 0)); 90 assertEquals(Infinity, Infinity / Math.max(-0, +0));
77 assertEquals(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Math.max(+0, - 0)); 91 assertEquals(Infinity, Infinity / Math.max(+0, -0));
78 assertEquals(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Math.max(+0, - 0, -1)); 92 assertEquals(Infinity, Infinity / Math.max(+0, -0, -1));
93 assertEquals(Infinity, Infinity / Math.max(-0, ZERO));
94 assertEquals(Infinity, Infinity / Math.max(ZERO, -0));
95 assertEquals(Infinity, Infinity / Math.max(ZERO, -0, -1));
79 assertEquals(1, Math.max(+0, -0, +1)); 96 assertEquals(1, Math.max(+0, -0, +1));
80 assertEquals(1, Math.max(+1, +0, -0)); 97 assertEquals(1, Math.max(+1, +0, -0));
81 assertEquals(1, Math.max(+0, +1, -0)); 98 assertEquals(1, Math.max(+0, +1, -0));
82 assertEquals(1, Math.max(-0, +1, +0)); 99 assertEquals(1, Math.max(-0, +1, +0));
83 assertNaN(Math.max('oxen')); 100 assertNaN(Math.max('oxen'));
84 assertNaN(Math.max('oxen', 1)); 101 assertNaN(Math.max('oxen', 1));
85 assertNaN(Math.max(1, 'oxen')); 102 assertNaN(Math.max(1, 'oxen'));
103
104 assertEquals(Infinity, 1/Math.max(ZERO, -0));
105 assertEquals(Infinity, 1/Math.max(-0, ZERO));
OLDNEW
« no previous file with comments | « src/math.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698