add_reuse_callsite.js revision 6:5a1b0714df0e
1238405Sjkim/*
2238405Sjkim * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3238405Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4238405Sjkim *
5238405Sjkim * This code is free software; you can redistribute it and/or modify it
6238405Sjkim * under the terms of the GNU General Public License version 2 only, as
7238405Sjkim * published by the Free Software Foundation.
8238405Sjkim *
9238405Sjkim * This code is distributed in the hope that it will be useful, but WITHOUT
10238405Sjkim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11238405Sjkim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12238405Sjkim * version 2 for more details (a copy is included in the LICENSE file that
13238405Sjkim * accompanied this code).
14238405Sjkim *
15238405Sjkim * You should have received a copy of the GNU General Public License version
16238405Sjkim * 2 along with this work; if not, write to the Free Software Foundation,
17238405Sjkim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18238405Sjkim *
19238405Sjkim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20238405Sjkim * or visit www.oracle.com if you need additional information or have any
21238405Sjkim * questions.
22238405Sjkim */
23238405Sjkim
24238405Sjkim/**
25238405Sjkim * Example of an add function that gets specialized to doubles
26238405Sjkim * if run with --optimize flag set
27238405Sjkim */
28238405Sjkim
29238405Sjkimfunction add(a,b) {
30238405Sjkim    return a + b;
31238405Sjkim}
32238405Sjkim
33238405Sjkim
34238405Sjkimfunction bench() {
35238405Sjkim    var sum = 1;
36238405Sjkim    for (var x = 0 ; x < 5e7 ; x++) {
37238405Sjkim	sum *= add(x,x + 1);
38238405Sjkim    }
39238405Sjkim    for (var x = 0; x < 5e7 ; x++) {
40238405Sjkim	sum *= add(x + 2, x + 3);
41238405Sjkim    }
42238405Sjkim    return sum;
43238405Sjkim}
44238405Sjkim
45238405Sjkimvar d = new Date;
46238405Sjkimprint(bench());
47238405Sjkimd = new Date - d;
48238405Sjkimprint("took " + d + " ms");
49238405Sjkim