├── JetStream ├── bigfib.cpp.js ├── cdjs.js ├── container.cpp.js ├── dry.c.js ├── float-mm.c.js ├── gcc-loops.cpp.js ├── hash-map.js ├── n-body.c.js ├── quicksort.c.js └── towers.c.js ├── JetStream3 ├── js-tokens.js ├── lazy-collections.js ├── raytrace-private-class-fields.js ├── raytrace-public-class-fields.js └── sync-file-system.js ├── Kraken ├── ai-astar.js ├── audio-beat-detection.js ├── audio-dft.js ├── audio-fft.js ├── audio-oscillator.js ├── imaging-darkroom.js ├── imaging-desaturate.js ├── imaging-gaussian-blur.js ├── json-parse-financial.js ├── json-stringify-tinderbox.js ├── stanford-crypto-aes.js ├── stanford-crypto-ccm.js ├── stanford-crypto-pbkdf2.js └── stanford-crypto-sha256-iterative.js ├── LongSpider ├── 3d-cube.js ├── 3d-morph.js ├── 3d-raytrace.js ├── access-binary-trees.js ├── access-fannkuch.js ├── access-nbody.js ├── access-nsieve.js ├── bitops-3bit-bits-in-byte.js ├── bitops-bits-in-byte.js ├── bitops-nsieve-bits.js ├── controlflow-recursive.js ├── crypto-aes.js ├── crypto-md5.js ├── crypto-sha1.js ├── date-format-tofte.js ├── date-format-xparb.js ├── hash-map.js ├── math-cordic.js ├── math-partial-sums.js ├── math-spectral-norm.js ├── string-base64.js ├── string-fasta.js └── string-tagcloud.js ├── MicroBench ├── array-destructuring-assignment-rest.js ├── array-destructuring-assignment.js ├── array-prototype-map.js ├── bound-call-00-args.js ├── bound-call-04-args.js ├── bound-call-16-args.js ├── call-00-args.js ├── call-01-args.js ├── call-02-args.js ├── call-03-args.js ├── call-04-args.js ├── call-16-args.js ├── call-32-args.js ├── for-in-indexed-properties.js ├── for-in-named-properties.js ├── for-of.js ├── object-keys.js ├── pic-get-own.js ├── pic-get-pchain.js ├── pic-put-own.js ├── pic-put-pchain.js ├── setter-in-prototype-chain.js └── strictly-equals-object.js ├── Octane ├── box2d.js ├── code-load.js ├── crypto.js ├── deltablue.js ├── earley-boyer.js ├── gbemu.js ├── mandreel.js ├── navier-stokes.js ├── pdfjs.js ├── raytrace.js ├── regexp.js ├── richards.js ├── splay.js ├── typescript.js └── zlib.js ├── RegExp ├── speedometer-jquery-regexp-1.js └── speedometer-jquery-regexp-2.js ├── SunSpider ├── 3d-cube.js ├── 3d-morph.js ├── 3d-raytrace.js ├── access-binary-trees.js ├── access-fannkuch.js ├── access-nbody.js ├── access-nsieve.js ├── bitops-3bit-bits-in-byte.js ├── bitops-bits-in-byte.js ├── bitops-bitwise-and.js ├── bitops-nsieve-bits.js ├── controlflow-recursive.js ├── crypto-aes.js ├── crypto-md5.js ├── crypto-sha1.js ├── date-format-tofte.js ├── date-format-xparb.js ├── math-cordic.js ├── math-partial-sums.js ├── math-spectral-norm.js ├── regexp-dna.js ├── string-base64.js ├── string-fasta.js ├── string-tagcloud.js ├── string-unpack-code.js └── string-validate-input.js ├── compare.py ├── requirements.txt └── run.py /JetStream3/sync-file-system.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 | * THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | "use strict"; 27 | 28 | function computeIsLittleEndian() { 29 | let buf = new ArrayBuffer(4); 30 | let dv = new DataView(buf); 31 | dv.setUint32(0, 0x11223344, true); 32 | let view = new Uint8Array(buf); 33 | return view[0] === 0x44; 34 | } 35 | 36 | const isLittleEndian = computeIsLittleEndian(); 37 | 38 | function randomFileContents(bytes = ((Math.random() * 128) >>> 0) + 2056) { 39 | let result = new ArrayBuffer(bytes); 40 | let view = new Uint8Array(result); 41 | for (let i = 0; i < bytes; ++i) 42 | view[i] = (Math.random() * 255) >>> 0; 43 | return new DataView(result); 44 | } 45 | 46 | class File { 47 | constructor(dataView, permissions) { 48 | this._data = dataView; 49 | } 50 | 51 | get data() { return this._data; } 52 | 53 | set data(dataView) { this._data = dataView; } 54 | 55 | swapByteOrder() { 56 | for (let i = 0; i < Math.floor(this.data.byteLength / 8) * 8; i += 8) { 57 | this.data.setFloat64(i, this.data.getFloat64(i, isLittleEndian), !isLittleEndian); 58 | } 59 | } 60 | } 61 | 62 | class Directory { 63 | constructor() { 64 | this.structure = new Map; 65 | } 66 | 67 | addFile(name, file) { 68 | let entry = this.structure.get(name); 69 | if (entry !== undefined) { 70 | if (entry instanceof File) 71 | throw new Error("Can't replace file with file."); 72 | if (entry instanceof Directory) 73 | throw new Error("Can't replace a file with a new directory."); 74 | throw new Error("Should not reach this code"); 75 | } 76 | 77 | this.structure.set(name, file); 78 | return file; 79 | } 80 | 81 | addDirectory(name, directory = new Directory) { 82 | let entry = this.structure.get(name); 83 | if (entry !== undefined) { 84 | if (entry instanceof File) 85 | throw new Error("Can't replace file with directory."); 86 | if (entry instanceof Directory) 87 | throw new Error("Can't replace directory with new directory."); 88 | throw new Error("Should not reach this code"); 89 | } 90 | 91 | this.structure.set(name, directory); 92 | return directory; 93 | } 94 | 95 | * ls() { 96 | for (let [name, entry] of this.structure) 97 | yield { name, entry, isDirectory: entry instanceof Directory }; 98 | } 99 | 100 | * forEachFile() { 101 | for (let item of this.ls()) { 102 | if (!item.isDirectory) 103 | yield item; 104 | } 105 | } 106 | 107 | * forEachFileRecursively() { 108 | for (let item of this.ls()) { 109 | if (item.isDirectory) 110 | yield* item.entry.forEachFileRecursively(); 111 | else 112 | yield item; 113 | } 114 | } 115 | 116 | * forEachDirectoryRecursively() { 117 | for (let item of this.ls()) { 118 | if (!item.isDirectory) 119 | continue; 120 | 121 | yield* item.entry.forEachDirectoryRecursively(); 122 | yield item; 123 | } 124 | } 125 | 126 | fileCount() { 127 | let count = 0; 128 | for (let item of this.ls()) { 129 | if (!item.isDirectory) 130 | ++count; 131 | } 132 | 133 | return count; 134 | } 135 | 136 | rm(name) { 137 | return this.structure.delete(name); 138 | } 139 | } 140 | 141 | function setupDirectory() { 142 | const fs = new Directory; 143 | let dirs = [fs]; 144 | for (let dir of dirs) { 145 | for (let i = 0; i < 8; ++i) { 146 | if (dirs.length < 250 && Math.random() >= 0.3) { 147 | dirs.push(dir.addDirectory(`dir-${i}`)); 148 | } 149 | } 150 | } 151 | 152 | for (let dir of dirs) { 153 | for (let i = 0; i < 5; ++i) { 154 | if (Math.random() >= 0.6) { 155 | dir.addFile(`file-${i}`, new File(randomFileContents())); 156 | } 157 | } 158 | } 159 | 160 | return fs; 161 | } 162 | 163 | class Benchmark { 164 | runIteration() { 165 | const fs = setupDirectory(); 166 | 167 | for (let { entry: file } of fs.forEachFileRecursively()) { 168 | file.swapByteOrder(); 169 | } 170 | 171 | for (let { name, entry: dir } of fs.forEachDirectoryRecursively()) { 172 | if (dir.fileCount() > 3) { 173 | for (let { name } of dir.forEachFile()) { 174 | let result = dir.rm(name); 175 | if (!result) 176 | throw new Error("rm should have returned true"); 177 | 178 | } 179 | } 180 | } 181 | } 182 | } 183 | 184 | for (let i = 0; i < 30; ++i) 185 | new Benchmark().runIteration(); 186 | -------------------------------------------------------------------------------- /Kraken/json-parse-financial.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | if(typeof(WScript) === "undefined") 27 | { 28 | var WScript = { 29 | Echo: print 30 | } 31 | } 32 | 33 | function record(time) { 34 | document.getElementById("console").innerHTML = time + "ms"; 35 | if (window.parent) { 36 | parent.recordResult(time); 37 | } 38 | } 39 | 40 | var data = 41 | "{\"summary\":{\"turnover\":0.3736,\"correlation2\":0." + 42 | "7147,\"concentration\":0.3652,\"beta\":0.8814,\"totalValue\":1.3" + 43 | "091078259E8,\"correlation\":0.7217},\"watchlist\":[],\"shortCash" + 44 | "\":-1611000,\"holdings\":[{\"type\":\"LONG\",\"commission\":1040" + 45 | ",\"cost\":9001920,\"quantity\":26000,\"lots\":[{\"marketCap\":\"" + 46 | "L\",\"industry\":\"TECHNOLOGY\",\"style\":\"G\",\"buyDate\":\"20" + 47 | "08-10-08 13:44:20.000\",\"quantity\":8000},{\"marketCap\":\"L\"," + 48 | "\"industry\":\"TECHNOLOGY\",\"style\":\"G\",\"buyDate\":\"2008-1" + 49 | "0-15 13:28:02.000\",\"quantity\":18000}],\"stock\":\"GOOG\"},{\"" + 50 | "type\":\"LONG\",\"commission\":8000,\"cost\":4672000,\"quantity" + 51 | "\":200000,\"lots\":[{\"marketCap\":\"L\",\"industry\":\"TECHNOLO" + 52 | "GY\",\"style\":\"G\",\"buyDate\":\"2008-10-15 13:28:54.000\",\"q" + 53 | "uantity\":200000}],\"stock\":\"MSFT\"},{\"type\":\"LONG\",\"comm" + 54 | "ission\":21877,\"cost\":1.001592313E7,\"quantity\":546919,\"lots" + 55 | "\":[{\"marketCap\":\"L\",\"industry\":\"FINANCIAL\",\"style\":\"" + 56 | "G\",\"buyDate\":\"2008-08-01 09:50:17.000\",\"quantity\":103092}" + 57 | ",{\"marketCap\":\"L\",\"industry\":\"FINANCIAL\",\"style\":\"G\"" + 58 | ",\"buyDate\":\"2008-08-18 10:31:34.000\",\"quantity\":49950},{\"" + 59 | "marketCap\":\"L\",\"industry\":\"FINANCIAL\",\"style\":\"G\",\"b" + 60 | "uyDate\":\"2008-08-29 09:35:22.000\",\"quantity\":45045},{\"mark" + 61 | "etCap\":\"L\",\"industry\":\"FINANCIAL\",\"style\":\"G\",\"buyDa" + 62 | "te\":\"2008-09-15 09:40:32.000\",\"quantity\":48400},{\"marketCa" + 63 | "p\":\"L\",\"industry\":\"FINANCIAL\",\"style\":\"G\",\"buyDate\"" + 64 | ":\"2008-10-06 11:21:50.000\",\"quantity\":432},{\"marketCap\":\"" + 65 | "L\",\"industry\":\"FINANCIAL\",\"style\":\"G\",\"buyDate\":\"200" + 66 | "8-10-15 13:30:05.000\",\"quantity\":300000}],\"stock\":\"UBS\"}," + 67 | "{\"type\":\"LONG\",\"commission\":4000,\"cost\":6604849.1,\"quan" + 68 | "tity\":122741,\"lots\":[{\"marketCap\":\"L\",\"industry\":\"SERV" + 69 | "ICES\",\"style\":\"V\",\"buyDate\":\"2008-04-26 04:44:34.000\"," + 70 | "\"quantity\":22741},{\"marketCap\":\"L\",\"industry\":\"SERVICES" + 71 | "\",\"style\":\"V\",\"buyDate\":\"2008-10-15 13:31:02.000\",\"qua" + 72 | "ntity\":100000}],\"stock\":\"V\"},{\"type\":\"LONG\",\"commissio" + 73 | "n\":2805,\"cost\":5005558.25,\"quantity\":70121,\"lots\":[{\"mar" + 74 | "ketCap\":\"M\",\"industry\":\"RETAIL\",\"style\":\"G\",\"buyDate" + 75 | "\":\"2008-10-10 10:48:36.000\",\"quantity\":121},{\"marketCap\":" + 76 | "\"M\",\"industry\":\"RETAIL\",\"style\":\"G\",\"buyDate\":\"2008" + 77 | "-10-15 13:33:44.000\",\"quantity\":70000}],\"stock\":\"LDG\"},{" + 78 | "\"type\":\"LONG\",\"commission\":10000,\"cost\":5382500,\"quanti" + 79 | "ty\":250000,\"lots\":[{\"marketCap\":\"L\",\"industry\":\"RETAIL" + 80 | "\",\"style\":\"V\",\"buyDate\":\"2008-10-15 13:34:30.000\",\"qua" + 81 | "ntity\":250000}],\"stock\":\"SWY\"},{\"type\":\"LONG\",\"commiss" + 82 | "ion\":1120,\"cost\":1240960,\"quantity\":28000,\"lots\":[{\"mark" + 83 | "etCap\":\"u\",\"industry\":\"ETF\",\"style\":\"B\",\"buyDate\":" + 84 | "\"2008-10-15 15:57:39.000\",\"quantity\":28000}],\"stock\":\"OIL" + 85 | "\"},{\"type\":\"LONG\",\"commission\":400,\"cost\":236800,\"quan" + 86 | "tity\":10000,\"lots\":[{\"marketCap\":\"M\",\"industry\":\"UTILI" + 87 | "TIES_AND_ENERGY\",\"style\":\"G\",\"buyDate\":\"2008-10-15 15:58" + 88 | ":03.000\",\"quantity\":10000}],\"stock\":\"COG\"},{\"type\":\"LO" + 89 | "NG\",\"commission\":3200,\"cost\":1369600,\"quantity\":80000,\"l" + 90 | "ots\":[{\"marketCap\":\"S\",\"industry\":\"UTILITIES_AND_ENERGY" + 91 | "\",\"style\":\"G\",\"buyDate\":\"2008-10-15 15:58:32.000\",\"qua" + 92 | "ntity\":80000}],\"stock\":\"CRZO\"},{\"type\":\"LONG\",\"commiss" + 93 | "ion\":429,\"cost\":108164.8,\"quantity\":10720,\"lots\":[{\"mark" + 94 | "etCap\":\"u\",\"industry\":\"FINANCIAL\",\"style\":\"V\",\"buyDa" + 95 | "te\":\"2008-10-16 09:37:06.000\",\"quantity\":10720}],\"stock\":" + 96 | "\"FGI\"},{\"type\":\"LONG\",\"commission\":1080,\"cost\":494910," + 97 | "\"quantity\":27000,\"lots\":[{\"marketCap\":\"L\",\"industry\":" + 98 | "\"RETAIL\",\"style\":\"V\",\"buyDate\":\"2008-10-16 09:37:06.000" + 99 | "\",\"quantity\":27000}],\"stock\":\"LOW\"},{\"type\":\"LONG\",\"" + 100 | "commission\":4080,\"cost\":4867440,\"quantity\":102000,\"lots\":" + 101 | "[{\"marketCap\":\"L\",\"industry\":\"HEALTHCARE\",\"style\":\"V" + 102 | "\",\"buyDate\":\"2008-10-16 09:37:06.000\",\"quantity\":102000}]" + 103 | ",\"stock\":\"AMGN\"},{\"type\":\"SHORT\",\"commission\":4000,\"" + 104 | "cost\":-1159000,\"quantity\":-100000,\"lots\":[{\"marketCap\":" + 105 | "\"L\",\"industry\":\"TECHNOLOGY\",\"style\":\"V\",\"buyDate\":" + 106 | "\"2008-10-16 09:37:06.000\",\"quantity\":-100000}],\"stock\":\"" + 107 | "AMAT\"},{\"type\":\"LONG\",\"commission\":2,\"cost\":5640002,\"" + 108 | "quantity\":50,\"lots\":[{\"marketCap\":\"L\",\"industry\":\"FIN" + 109 | "ANCIAL\",\"style\":\"B\",\"buyDate\":\"2008-10-16 09:37:06.000" + 110 | "\",\"quantity\":50}],\"stock\":\"BRKA\"},{\"type\":\"SHORT\",\"" + 111 | "commission\":4000,\"cost\":-436000,\"quantity\":-100000,\"lots" + 112 | "\":[{\"marketCap\":\"M\",\"industry\":\"TRANSPORTATION\",\"styl" + 113 | "e\":\"G\",\"buyDate\":\"2008-10-16 09:37:06.000\",\"quantity\":-" + 114 | "100000}],\"stock\":\"JBLU\"},{\"type\":\"LONG\",\"commission\":8" + 115 | "000,\"cost\":1.1534E7,\"quantity\":200000,\"lots\":[{\"marketCap" + 116 | "\":\"S\",\"industry\":\"FINANCIAL\",\"style\":\"G\",\"buyDate\":" + 117 | "\"2008-10-16 14:35:24.000\",\"quantity\":200000}],\"stock\":\"US" + 118 | "O\"},{\"type\":\"LONG\",\"commission\":4000,\"cost\":1.0129E7,\"" + 119 | "quantity\":100000,\"lots\":[{\"marketCap\":\"L\",\"industry\":\"" + 120 | "TECHNOLOGY\",\"style\":\"G\",\"buyDate\":\"2008-10-15 13:28:26.0" + 121 | "00\",\"quantity\":50000},{\"marketCap\":\"L\",\"industry\":\"TEC" + 122 | "HNOLOGY\",\"style\":\"G\",\"buyDate\":\"2008-10-17 09:33:09.000" + 123 | "\",\"quantity\":50000}],\"stock\":\"AAPL\"},{\"type\":\"LONG\"," + 124 | "\"commission\":1868,\"cost\":9971367.2,\"quantity\":54280,\"lots" + 125 | "\":[{\"marketCap\":\"L\",\"industry\":\"SERVICES\",\"style\":\"G" + 126 | "\",\"buyDate\":\"2008-04-26 04:44:34.000\",\"quantity\":7580},{" + 127 | "\"marketCap\":\"L\",\"industry\":\"SERVICES\",\"style\":\"G\",\"" + 128 | "buyDate\":\"2008-05-29 09:50:28.000\",\"quantity\":7500},{\"mark" + 129 | "etCap\":\"L\",\"industry\":\"SERVICES\",\"style\":\"G\",\"buyDat" + 130 | "e\":\"2008-10-15 13:30:38.000\",\"quantity\":33000},{\"marketCap" + 131 | "\":\"L\",\"industry\":\"SERVICES\",\"style\":\"G\",\"buyDate\":" + 132 | "\"2008-10-17 09:33:09.000\",\"quantity\":6200}],\"stock\":\"MA\"" + 133 | "}],\"longCash\":4.600368106E7,\"ownerId\":8,\"pendingOrders\":[{" + 134 | "\"total\":487000,\"type\":\"cover\",\"subtotal\":483000,\"price" + 135 | "\":4.83,\"commission\":4000,\"date\":\"2008-10-17 23:56:06.000\"" + 136 | ",\"quantity\":100000,\"expires\":\"2008-10-20 16:00:00.000\",\"s" + 137 | "tock\":\"JBLU\",\"id\":182375},{\"total\":6271600,\"type\":\"buy" + 138 | "\",\"subtotal\":6270000,\"price\":156.75,\"commission\":1600,\"d" + 139 | "ate\":\"2008-10-17 23:56:40.000\",\"quantity\":40000,\"expires\"" + 140 | ":\"2008-10-20 16:00:00.000\",\"stock\":\"MA\",\"id\":182376}],\"" + 141 | "inceptionDate\":\"2008-04-26 04:44:29.000\",\"withdrawals\":0,\"" + 142 | "id\":219948,\"deposits\":0}"; 143 | 144 | 145 | var _sunSpiderStartDate = new Date(); 146 | 147 | 148 | for (var i = 0; i < 1000; i++) { 149 | var x = JSON.parse(data); 150 | } 151 | 152 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 153 | 154 | console.log("### TIME:", _sunSpiderInterval, "ms"); 155 | -------------------------------------------------------------------------------- /LongSpider/3d-cube.js: -------------------------------------------------------------------------------- 1 | // 3D Cube Rotation 2 | // http://www.speich.net/computer/moztesting/3d.htm 3 | // Created by Simon Speich 4 | 5 | var Q = new Array(); 6 | var MTrans = new Array(); // transformation matrix 7 | var MQube = new Array(); // position information of qube 8 | var I = new Array(); // entity matrix 9 | var Origin = new Object(); 10 | var Testing = new Object(); 11 | var LoopTimer; 12 | 13 | var validation = { 14 | 20: 2889.0000000000045, 15 | 40: 2889.0000000000055, 16 | 80: 2889.000000000005, 17 | 160: 2889.0000000000055, 18 | 320: 2889.000000000006, 19 | 640: 2889.000000000013, 20 | 1280: 2888.9999999999923, 21 | 2560: 2888.9999999999463, 22 | 5120: 2889.0000000000405, 23 | 10240: 2889.0000000002497, 24 | 20480: 2889.0000000000405, 25 | 40960: 2888.999999999462, 26 | 81920: 2888.999999999193, 27 | 163840: 2888.999999998356 28 | }; 29 | 30 | var DisplArea = new Object(); 31 | DisplArea.Width = 300; 32 | DisplArea.Height = 300; 33 | 34 | function DrawLine(From, To) { 35 | var x1 = From.V[0]; 36 | var x2 = To.V[0]; 37 | var y1 = From.V[1]; 38 | var y2 = To.V[1]; 39 | var dx = Math.abs(x2 - x1); 40 | var dy = Math.abs(y2 - y1); 41 | var x = x1; 42 | var y = y1; 43 | var IncX1, IncY1; 44 | var IncX2, IncY2; 45 | var Den; 46 | var Num; 47 | var NumAdd; 48 | var NumPix; 49 | 50 | if (x2 >= x1) { IncX1 = 1; IncX2 = 1; } 51 | else { IncX1 = -1; IncX2 = -1; } 52 | if (y2 >= y1) { IncY1 = 1; IncY2 = 1; } 53 | else { IncY1 = -1; IncY2 = -1; } 54 | if (dx >= dy) { 55 | IncX1 = 0; 56 | IncY2 = 0; 57 | Den = dx; 58 | Num = dx / 2; 59 | NumAdd = dy; 60 | NumPix = dx; 61 | } 62 | else { 63 | IncX2 = 0; 64 | IncY1 = 0; 65 | Den = dy; 66 | Num = dy / 2; 67 | NumAdd = dx; 68 | NumPix = dy; 69 | } 70 | 71 | NumPix = Math.round(Q.LastPx + NumPix); 72 | 73 | var i = Q.LastPx; 74 | for (; i < NumPix; i++) { 75 | Num += NumAdd; 76 | if (Num >= Den) { 77 | Num -= Den; 78 | x += IncX1; 79 | y += IncY1; 80 | } 81 | x += IncX2; 82 | y += IncY2; 83 | } 84 | Q.LastPx = NumPix; 85 | } 86 | 87 | function CalcCross(V0, V1) { 88 | var Cross = new Array(); 89 | Cross[0] = V0[1]*V1[2] - V0[2]*V1[1]; 90 | Cross[1] = V0[2]*V1[0] - V0[0]*V1[2]; 91 | Cross[2] = V0[0]*V1[1] - V0[1]*V1[0]; 92 | return Cross; 93 | } 94 | 95 | function CalcNormal(V0, V1, V2) { 96 | var A = new Array(); var B = new Array(); 97 | for (var i = 0; i < 3; i++) { 98 | A[i] = V0[i] - V1[i]; 99 | B[i] = V2[i] - V1[i]; 100 | } 101 | A = CalcCross(A, B); 102 | var Length = Math.sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]); 103 | for (var i = 0; i < 3; i++) A[i] = A[i] / Length; 104 | A[3] = 1; 105 | return A; 106 | } 107 | 108 | function CreateP(X,Y,Z) { 109 | this.V = [X,Y,Z,1]; 110 | } 111 | 112 | // multiplies two matrices 113 | function MMulti(M1, M2) { 114 | var M = [[],[],[],[]]; 115 | var i = 0; 116 | var j = 0; 117 | for (; i < 4; i++) { 118 | j = 0; 119 | for (; j < 4; j++) M[i][j] = M1[i][0] * M2[0][j] + M1[i][1] * M2[1][j] + M1[i][2] * M2[2][j] + M1[i][3] * M2[3][j]; 120 | } 121 | return M; 122 | } 123 | 124 | //multiplies matrix with vector 125 | function VMulti(M, V) { 126 | var Vect = new Array(); 127 | var i = 0; 128 | for (;i < 4; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2] + M[i][3] * V[3]; 129 | return Vect; 130 | } 131 | 132 | function VMulti2(M, V) { 133 | var Vect = new Array(); 134 | var i = 0; 135 | for (;i < 3; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2]; 136 | return Vect; 137 | } 138 | 139 | // add to matrices 140 | function MAdd(M1, M2) { 141 | var M = [[],[],[],[]]; 142 | var i = 0; 143 | var j = 0; 144 | for (; i < 4; i++) { 145 | j = 0; 146 | for (; j < 4; j++) M[i][j] = M1[i][j] + M2[i][j]; 147 | } 148 | return M; 149 | } 150 | 151 | function Translate(M, Dx, Dy, Dz) { 152 | var T = [ 153 | [1,0,0,Dx], 154 | [0,1,0,Dy], 155 | [0,0,1,Dz], 156 | [0,0,0,1] 157 | ]; 158 | return MMulti(T, M); 159 | } 160 | 161 | function RotateX(M, Phi) { 162 | var a = Phi; 163 | a *= Math.PI / 180; 164 | var Cos = Math.cos(a); 165 | var Sin = Math.sin(a); 166 | var R = [ 167 | [1,0,0,0], 168 | [0,Cos,-Sin,0], 169 | [0,Sin,Cos,0], 170 | [0,0,0,1] 171 | ]; 172 | return MMulti(R, M); 173 | } 174 | 175 | function RotateY(M, Phi) { 176 | var a = Phi; 177 | a *= Math.PI / 180; 178 | var Cos = Math.cos(a); 179 | var Sin = Math.sin(a); 180 | var R = [ 181 | [Cos,0,Sin,0], 182 | [0,1,0,0], 183 | [-Sin,0,Cos,0], 184 | [0,0,0,1] 185 | ]; 186 | return MMulti(R, M); 187 | } 188 | 189 | function RotateZ(M, Phi) { 190 | var a = Phi; 191 | a *= Math.PI / 180; 192 | var Cos = Math.cos(a); 193 | var Sin = Math.sin(a); 194 | var R = [ 195 | [Cos,-Sin,0,0], 196 | [Sin,Cos,0,0], 197 | [0,0,1,0], 198 | [0,0,0,1] 199 | ]; 200 | return MMulti(R, M); 201 | } 202 | 203 | function DrawQube() { 204 | // calc current normals 205 | var CurN = new Array(); 206 | var i = 5; 207 | Q.LastPx = 0; 208 | for (; i > -1; i--) CurN[i] = VMulti2(MQube, Q.Normal[i]); 209 | if (CurN[0][2] < 0) { 210 | if (!Q.Line[0]) { DrawLine(Q[0], Q[1]); Q.Line[0] = true; }; 211 | if (!Q.Line[1]) { DrawLine(Q[1], Q[2]); Q.Line[1] = true; }; 212 | if (!Q.Line[2]) { DrawLine(Q[2], Q[3]); Q.Line[2] = true; }; 213 | if (!Q.Line[3]) { DrawLine(Q[3], Q[0]); Q.Line[3] = true; }; 214 | } 215 | if (CurN[1][2] < 0) { 216 | if (!Q.Line[2]) { DrawLine(Q[3], Q[2]); Q.Line[2] = true; }; 217 | if (!Q.Line[9]) { DrawLine(Q[2], Q[6]); Q.Line[9] = true; }; 218 | if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; }; 219 | if (!Q.Line[10]) { DrawLine(Q[7], Q[3]); Q.Line[10] = true; }; 220 | } 221 | if (CurN[2][2] < 0) { 222 | if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; }; 223 | if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; }; 224 | if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; }; 225 | if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; }; 226 | } 227 | if (CurN[3][2] < 0) { 228 | if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; }; 229 | if (!Q.Line[8]) { DrawLine(Q[5], Q[1]); Q.Line[8] = true; }; 230 | if (!Q.Line[0]) { DrawLine(Q[1], Q[0]); Q.Line[0] = true; }; 231 | if (!Q.Line[11]) { DrawLine(Q[0], Q[4]); Q.Line[11] = true; }; 232 | } 233 | if (CurN[4][2] < 0) { 234 | if (!Q.Line[11]) { DrawLine(Q[4], Q[0]); Q.Line[11] = true; }; 235 | if (!Q.Line[3]) { DrawLine(Q[0], Q[3]); Q.Line[3] = true; }; 236 | if (!Q.Line[10]) { DrawLine(Q[3], Q[7]); Q.Line[10] = true; }; 237 | if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; }; 238 | } 239 | if (CurN[5][2] < 0) { 240 | if (!Q.Line[8]) { DrawLine(Q[1], Q[5]); Q.Line[8] = true; }; 241 | if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; }; 242 | if (!Q.Line[9]) { DrawLine(Q[6], Q[2]); Q.Line[9] = true; }; 243 | if (!Q.Line[1]) { DrawLine(Q[2], Q[1]); Q.Line[1] = true; }; 244 | } 245 | Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false]; 246 | Q.LastPx = 0; 247 | } 248 | 249 | function Loop() { 250 | if (Testing.LoopCount > Testing.LoopMax) return; 251 | var TestingStr = String(Testing.LoopCount); 252 | while (TestingStr.length < 3) TestingStr = "0" + TestingStr; 253 | MTrans = Translate(I, -Q[8].V[0], -Q[8].V[1], -Q[8].V[2]); 254 | MTrans = RotateX(MTrans, 1); 255 | MTrans = RotateY(MTrans, 3); 256 | MTrans = RotateZ(MTrans, 5); 257 | MTrans = Translate(MTrans, Q[8].V[0], Q[8].V[1], Q[8].V[2]); 258 | MQube = MMulti(MTrans, MQube); 259 | var i = 8; 260 | for (; i > -1; i--) { 261 | Q[i].V = VMulti(MTrans, Q[i].V); 262 | } 263 | DrawQube(); 264 | Testing.LoopCount++; 265 | Loop(); 266 | } 267 | 268 | function Init(CubeSize) { 269 | // init/reset vars 270 | Origin.V = [150,150,20,1]; 271 | Testing.LoopCount = 0; 272 | Testing.LoopMax = 50; 273 | Testing.TimeMax = 0; 274 | Testing.TimeAvg = 0; 275 | Testing.TimeMin = 0; 276 | Testing.TimeTemp = 0; 277 | Testing.TimeTotal = 0; 278 | Testing.Init = false; 279 | 280 | // transformation matrix 281 | MTrans = [ 282 | [1,0,0,0], 283 | [0,1,0,0], 284 | [0,0,1,0], 285 | [0,0,0,1] 286 | ]; 287 | 288 | // position information of qube 289 | MQube = [ 290 | [1,0,0,0], 291 | [0,1,0,0], 292 | [0,0,1,0], 293 | [0,0,0,1] 294 | ]; 295 | 296 | // entity matrix 297 | I = [ 298 | [1,0,0,0], 299 | [0,1,0,0], 300 | [0,0,1,0], 301 | [0,0,0,1] 302 | ]; 303 | 304 | // create qube 305 | Q[0] = new CreateP(-CubeSize,-CubeSize, CubeSize); 306 | Q[1] = new CreateP(-CubeSize, CubeSize, CubeSize); 307 | Q[2] = new CreateP( CubeSize, CubeSize, CubeSize); 308 | Q[3] = new CreateP( CubeSize,-CubeSize, CubeSize); 309 | Q[4] = new CreateP(-CubeSize,-CubeSize,-CubeSize); 310 | Q[5] = new CreateP(-CubeSize, CubeSize,-CubeSize); 311 | Q[6] = new CreateP( CubeSize, CubeSize,-CubeSize); 312 | Q[7] = new CreateP( CubeSize,-CubeSize,-CubeSize); 313 | 314 | // center of gravity 315 | Q[8] = new CreateP(0, 0, 0); 316 | 317 | // anti-clockwise edge check 318 | Q.Edge = [[0,1,2],[3,2,6],[7,6,5],[4,5,1],[4,0,3],[1,5,6]]; 319 | 320 | // calculate squad normals 321 | Q.Normal = new Array(); 322 | for (var i = 0; i < Q.Edge.length; i++) Q.Normal[i] = CalcNormal(Q[Q.Edge[i][0]].V, Q[Q.Edge[i][1]].V, Q[Q.Edge[i][2]].V); 323 | 324 | // line drawn ? 325 | Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false]; 326 | 327 | // create line pixels 328 | Q.NumPx = 9 * 2 * CubeSize; 329 | for (var i = 0; i < Q.NumPx; i++) CreateP(0,0,0); 330 | 331 | MTrans = Translate(MTrans, Origin.V[0], Origin.V[1], Origin.V[2]); 332 | MQube = MMulti(MTrans, MQube); 333 | 334 | var i = 0; 335 | for (; i < 9; i++) { 336 | Q[i].V = VMulti(MTrans, Q[i].V); 337 | } 338 | DrawQube(); 339 | Testing.Init = true; 340 | Loop(); 341 | 342 | // Perform a simple sum-based verification. 343 | var sum = 0; 344 | for (var i = 0; i < Q.length; ++i) { 345 | var vector = Q[i].V; 346 | for (var j = 0; j < vector.length; ++j) 347 | sum += vector[j]; 348 | } 349 | if (sum != validation[CubeSize]) 350 | throw "Error: bad vector sum for CubeSize = " + CubeSize + "; expected " + validation[CubeSize] + " but got " + sum; 351 | } 352 | 353 | for ( var i = 20; i <= 260000; i *= 2 ) { 354 | Init(i); 355 | } 356 | 357 | Q = null; 358 | MTrans = null; 359 | MQube = null; 360 | I = null; 361 | Origin = null; 362 | Testing = null; 363 | LoopTime = null; 364 | DisplArea = null; 365 | 366 | -------------------------------------------------------------------------------- /LongSpider/3d-morph.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | var loops = 3500 27 | var nx = 120 28 | var nz = 120 29 | 30 | function morph(a, f) { 31 | var PI2nx = Math.PI * 8/nx 32 | var sin = Math.sin 33 | var f30 = -(50 * sin(f*Math.PI*2)) 34 | 35 | for (var i = 0; i < nz; ++i) { 36 | for (var j = 0; j < nx; ++j) { 37 | a[3*(i*nx+j)+1] = sin((j-1) * PI2nx ) * -f30 38 | } 39 | } 40 | } 41 | 42 | 43 | var a = Array() 44 | for (var i=0; i < nx*nz*3; ++i) 45 | a[i] = 0 46 | 47 | for (var i = 0; i < loops; ++i) { 48 | morph(a, i/loops) 49 | } 50 | 51 | // This has to be an approximate test since ECMAscript doesn't formally specify 52 | // what sin() returns. Even if it did specify something like for example what Java 7 53 | // says - that sin() has to return a value within 1 ulp of exact - then we still 54 | // would not be able to do an exact test here since that would allow for just enough 55 | // low-bit slop to create possibly big errors due to testOutput being a sum. 56 | 57 | var expectedResults = [ 58 | { value: 0.018662099703860055, total: 0.018662099703860055 }, // 0 59 | { value: 0, total: 0.018662099703860055 }, // 1 60 | { value: -0.018662099703860055, total: 0 }, // 2 61 | { value: -0.03650857609997156, total: -0.03650857609997156 }, // 3 62 | { value: -0.05275945253292943, total: -0.08926802863290098 }, // 4 63 | { value: -0.06670448772225647, total: -0.15597251635515746 }, // 5 64 | { value: -0.07773421671447613, total: -0.23370673306963358 }, // 6 65 | { value: -0.08536658742611654, total: -0.3190733204957501 }, // 7 66 | { value: -0.08926802863290098, total: -0.40834134912865105 }, // 8 67 | { value: -0.089268028632901, total: -0.49760937776155206 }, // 9 68 | { value: -0.08536658742611655, total: -0.5829759651876686 }, // 10 69 | { value: -0.07773421671447614, total: -0.6607101819021447 }, // 11 70 | { value: -0.06670448772225651, total: -0.7274146696244013 }, // 12 71 | { value: -0.052759452532929435, total: -0.7801741221573307 }, // 13 72 | { value: -0.03650857609997158, total: -0.8166826982573023 }, // 14 73 | { value: -0.018662099703860093, total: -0.8353447979611625 }, // 15 74 | { value: -1.0992398059873222e-17, total: -0.8353447979611625 }, // 16 75 | { value: 0.018662099703860034, total: -0.8166826982573024 }, // 17 76 | { value: 0.036508576099971525, total: -0.780174122157331 }, // 18 77 | { value: 0.052759452532929414, total: -0.7274146696244015 }, // 19 78 | { value: 0.06670448772225647, total: -0.660710181902145 }, // 20 79 | { value: 0.0777342167144761, total: -0.5829759651876689 }, // 21 80 | { value: 0.08536658742611654, total: -0.4976093777615524 }, // 22 81 | { value: 0.08926802863290098, total: -0.4083413491286514 }, // 23 82 | { value: 0.089268028632901, total: -0.3190733204957504 }, // 24 83 | { value: 0.08536658742611655, total: -0.23370673306963383 }, // 25 84 | { value: 0.07773421671447615, total: -0.1559725163551577 }, // 26 85 | { value: 0.06670448772225653, total: -0.08926802863290116 }, // 27 86 | { value: 0.052759452532929435, total: -0.036508576099971726 }, // 28 87 | { value: 0.03650857609997163, total: -9.71445146547012e-17 }, // 29 88 | { value: 0.018662099703860107, total: 0.01866209970386001 }, // 30 89 | { value: 2.1984796119746444e-17, total: 0.01866209970386003 }, // 31 90 | { value: -0.018662099703859986, total: 4.5102810375396984e-17 }, // 32 91 | { value: -0.03650857609997152, total: -0.036508576099971476 }, // 33 92 | { value: -0.05275945253292941, total: -0.08926802863290088 }, // 34 93 | { value: -0.06670448772225643, total: -0.1559725163551573 }, // 35 94 | { value: -0.0777342167144761, total: -0.2337067330696334 }, // 36 95 | { value: -0.08536658742611652, total: -0.31907332049574993 }, // 37 96 | { value: -0.08926802863290098, total: -0.40834134912865094 }, // 38 97 | { value: -0.089268028632901, total: -0.49760937776155195 }, // 39 98 | { value: -0.08536658742611655, total: -0.5829759651876685 }, // 40 99 | { value: -0.07773421671447617, total: -0.6607101819021446 }, // 41 100 | { value: -0.06670448772225658, total: -0.7274146696244012 }, // 42 101 | { value: -0.05275945253292945, total: -0.7801741221573306 }, // 43 102 | { value: -0.03650857609997164, total: -0.8166826982573022 }, // 44 103 | { value: -0.018662099703860194, total: -0.8353447979611625 }, // 45 104 | { value: -3.2977194179619666e-17, total: -0.8353447979611625 }, // 46 105 | { value: 0.018662099703859975, total: -0.8166826982573024 }, // 47 106 | { value: 0.036508576099971435, total: -0.7801741221573311 }, // 48 107 | { value: 0.0527594525329294, total: -0.7274146696244017 }, // 49 108 | { value: 0.06670448772225643, total: -0.6607101819021453 }, // 50 109 | { value: 0.07773421671447606, total: -0.5829759651876691 }, // 51 110 | { value: 0.08536658742611652, total: -0.4976093777615526 }, // 52 111 | { value: 0.08926802863290097, total: -0.40834134912865167 }, // 53 112 | { value: 0.08926802863290101, total: -0.31907332049575066 }, // 54 113 | { value: 0.08536658742611655, total: -0.2337067330696341 }, // 55 114 | { value: 0.07773421671447617, total: -0.15597251635515794 }, // 56 115 | { value: 0.06670448772225658, total: -0.08926802863290136 }, // 57 116 | { value: 0.052759452532929456, total: -0.0365085760999719 }, // 58 117 | { value: 0.03650857609997165, total: -2.498001805406602e-16 }, // 59 118 | { value: 0.018662099703860208, total: 0.018662099703859958 }, // 60 119 | { value: 4.396959223949289e-17, total: 0.018662099703860003 }, // 61 120 | { value: -0.01866209970385996, total: 4.163336342344337e-17 }, // 62 121 | { value: -0.03650857609997142, total: -0.03650857609997138 }, // 63 122 | { value: -0.0527594525329294, total: -0.08926802863290079 }, // 64 123 | { value: -0.06670448772225641, total: -0.1559725163551572 }, // 65 124 | { value: -0.07773421671447604, total: -0.23370673306963324 }, // 66 125 | { value: -0.08536658742611652, total: -0.31907332049574977 }, // 67 126 | { value: -0.08926802863290097, total: -0.4083413491286507 }, // 68 127 | { value: -0.08926802863290101, total: -0.49760937776155173 }, // 69 128 | { value: -0.08536658742611655, total: -0.5829759651876683 }, // 70 129 | { value: -0.07773421671447618, total: -0.6607101819021445 }, // 71 130 | { value: -0.06670448772225658, total: -0.727414669624401 }, // 72 131 | { value: -0.05275945253292948, total: -0.7801741221573305 }, // 73 132 | { value: -0.036508576099971664, total: -0.8166826982573022 }, // 74 133 | { value: -0.018662099703860215, total: -0.8353447979611625 }, // 75 134 | { value: -5.496199029936611e-17, total: -0.8353447979611625 }, // 76 135 | { value: 0.01866209970385995, total: -0.8166826982573026 }, // 77 136 | { value: 0.036508576099971414, total: -0.7801741221573312 }, // 78 137 | { value: 0.05275945253292938, total: -0.7274146696244018 }, // 79 138 | { value: 0.0667044877222563, total: -0.6607101819021455 }, // 80 139 | { value: 0.07773421671447604, total: -0.5829759651876695 }, // 81 140 | { value: 0.08536658742611652, total: -0.49760937776155295 }, // 82 141 | { value: 0.08926802863290097, total: -0.408341349128652 }, // 83 142 | { value: 0.08926802863290101, total: -0.319073320495751 }, // 84 143 | { value: 0.08536658742611655, total: -0.23370673306963444 }, // 85 144 | { value: 0.07773421671447626, total: -0.1559725163551582 }, // 86 145 | { value: 0.0667044877222566, total: -0.08926802863290159 }, // 87 146 | { value: 0.05275945253292948, total: -0.036508576099972115 }, // 88 147 | { value: 0.036508576099971816, total: -2.983724378680108e-16 }, // 89 148 | { value: 0.018662099703860225, total: 0.018662099703859927 }, // 90 149 | { value: 6.595438835923933e-17, total: 0.018662099703859993 }, // 91 150 | { value: -0.018662099703859788, total: 2.0469737016526324e-16 }, // 92 151 | { value: -0.0365085760999714, total: -0.0365085760999712 }, // 93 152 | { value: -0.052759452532929366, total: -0.08926802863290056 }, // 94 153 | { value: -0.06670448772225629, total: -0.15597251635515685 }, // 95 154 | { value: -0.07773421671447604, total: -0.2337067330696329 }, // 96 155 | { value: -0.08536658742611652, total: -0.31907332049574944 }, // 97 156 | { value: -0.08926802863290095, total: -0.4083413491286504 }, // 98 157 | { value: -0.08926802863290101, total: -0.4976093777615514 }, // 99 158 | { value: -0.08536658742611657, total: -0.5829759651876679 }, // 100 159 | { value: -0.07773421671447626, total: -0.6607101819021441 }, // 101 160 | { value: -0.06670448772225661, total: -0.7274146696244007 }, // 102 161 | { value: -0.052759452532929484, total: -0.7801741221573302 }, // 103 162 | { value: -0.03650857609997182, total: -0.816682698257302 }, // 104 163 | { value: -0.01866209970386024, total: -0.8353447979611622 }, // 105 164 | { value: -7.694678641911255e-17, total: -0.8353447979611623 }, // 106 165 | { value: 0.018662099703859774, total: -0.8166826982573026 }, // 107 166 | { value: 0.0365085760999714, total: -0.7801741221573312 }, // 108 167 | { value: 0.05275945253292936, total: -0.7274146696244018 }, // 109 168 | { value: 0.06670448772225629, total: -0.6607101819021455 }, // 110 169 | { value: 0.07773421671447603, total: -0.5829759651876695 }, // 111 170 | { value: 0.08536658742611652, total: -0.49760937776155295 }, // 112 171 | { value: 0.08926802863290095, total: -0.408341349128652 }, // 113 172 | { value: 0.08926802863290101, total: -0.319073320495751 }, // 114 173 | { value: 0.08536658742611657, total: -0.2337067330696344 }, // 115 174 | { value: 0.07773421671447626, total: -0.15597251635515813 }, // 116 175 | { value: 0.06670448772225661, total: -0.08926802863290152 }, // 117 176 | { value: 0.0527594525329295, total: -0.036508576099972025 }, // 118 177 | { value: 0.03650857609997184, total: -1.8735013540549517e-16 }, // 119 178 | ]; 179 | 180 | var valueError = 0.00000000000001; 181 | var totalError = 0.0000000000001; 182 | 183 | function expect(i, value, total) { 184 | var data = expectedResults; 185 | var valueDiff = Math.abs(value - data[i].value); 186 | var totalDiff = Math.abs(total - data[i].total); 187 | 188 | var err = null; 189 | if (valueDiff > valueError && totalDiff > totalError) 190 | err = " [" + i + "] value a:" + value + " e:" + data[i].value + " | d:" + valueDiff + ", total a:" + total + " e:" + data[i].total + " | d: " + totalDiff; 191 | else if (valueDiff > valueError) 192 | err = " [" + i + "] value a:" + value + " e:" + data[i].value + " | d:" + valueDiff; 193 | else if (totalDiff > totalError) 194 | err = " [" + i + "] total a:" + total + " e:" + data[i].total + " | d: " + totalDiff; 195 | 196 | if (err) 197 | throw err; 198 | } 199 | 200 | testOutput = 0; 201 | for (var i = 0; i < nx; i++) { 202 | var value = a[3*(i*nx+i)+1]; 203 | testOutput += value; 204 | expect(i, value, testOutput); 205 | } 206 | a = null; 207 | -------------------------------------------------------------------------------- /LongSpider/access-binary-trees.js: -------------------------------------------------------------------------------- 1 | /* The Great Computer Language Shootout 2 | http://shootout.alioth.debian.org/ 3 | contributed by Isaac Gouy */ 4 | 5 | function TreeNode(left,right,item){ 6 | this.left = left; 7 | this.right = right; 8 | this.item = item; 9 | } 10 | 11 | TreeNode.prototype.itemCheck = function(){ 12 | if (this.left==null) return this.item; 13 | else return this.item + this.left.itemCheck() - this.right.itemCheck(); 14 | } 15 | 16 | function bottomUpTree(item,depth){ 17 | if (depth>0){ 18 | return new TreeNode( 19 | bottomUpTree(2*item-1, depth-1) 20 | ,bottomUpTree(2*item, depth-1) 21 | ,item 22 | ); 23 | } 24 | else { 25 | return new TreeNode(null,null,item); 26 | } 27 | } 28 | 29 | var ret = 0; 30 | 31 | for ( var n = 4; n <= 16; n += 1 ) { 32 | var minDepth = 4; 33 | var maxDepth = Math.max(minDepth + 2, n); 34 | var stretchDepth = maxDepth + 1; 35 | 36 | var check = bottomUpTree(0,stretchDepth).itemCheck(); 37 | 38 | var longLivedTree = bottomUpTree(0,maxDepth); 39 | for (var depth=minDepth; depth<=maxDepth; depth+=2){ 40 | var iterations = 1 << (maxDepth - depth + minDepth); 41 | 42 | check = 0; 43 | for (var i=1; i<=iterations; i++){ 44 | check += bottomUpTree(i,depth).itemCheck(); 45 | check += bottomUpTree(-i,depth).itemCheck(); 46 | } 47 | } 48 | 49 | ret += longLivedTree.itemCheck(); 50 | } 51 | 52 | var expected = -13; 53 | if (ret != expected) 54 | throw "ERROR: bad result: expected " + expected + " but got " + ret; 55 | -------------------------------------------------------------------------------- /LongSpider/access-fannkuch.js: -------------------------------------------------------------------------------- 1 | /* The Great Computer Language Shootout 2 | http://shootout.alioth.debian.org/ 3 | contributed by Isaac Gouy */ 4 | 5 | function fannkuch(n) { 6 | var check = 0; 7 | var perm = Array(n); 8 | var perm1 = Array(n); 9 | var count = Array(n); 10 | var maxPerm = Array(n); 11 | var maxFlipsCount = 0; 12 | var m = n - 1; 13 | 14 | for (var i = 0; i < n; i++) perm1[i] = i; 15 | var r = n; 16 | 17 | while (true) { 18 | // write-out the first 30 permutations 19 | if (check < 30){ 20 | var s = ""; 21 | for(var i=0; i> 1; 34 | for (var i = 0; i < k2; i++) { 35 | var temp = perm[i]; perm[i] = perm[k - i]; perm[k - i] = temp; 36 | } 37 | flipsCount++; 38 | } 39 | 40 | if (flipsCount > maxFlipsCount) { 41 | maxFlipsCount = flipsCount; 42 | for (var i = 0; i < n; i++) maxPerm[i] = perm1[i]; 43 | } 44 | } 45 | 46 | while (true) { 47 | if (r == n) return maxFlipsCount; 48 | var perm0 = perm1[0]; 49 | var i = 0; 50 | while (i < r) { 51 | var j = i + 1; 52 | perm1[i] = perm1[j]; 53 | i = j; 54 | } 55 | perm1[r] = perm0; 56 | 57 | count[r] = count[r] - 1; 58 | if (count[r] > 0) break; 59 | r++; 60 | } 61 | } 62 | } 63 | 64 | var n = 10; 65 | var ret = fannkuch(n); 66 | 67 | var expected = 38; 68 | if (ret != expected) 69 | throw "ERROR: bad result: expected " + expected + " but got " + ret; 70 | 71 | -------------------------------------------------------------------------------- /LongSpider/access-nbody.js: -------------------------------------------------------------------------------- 1 | /* The Great Computer Language Shootout 2 | http://shootout.alioth.debian.org/ 3 | contributed by Isaac Gouy */ 4 | 5 | var PI = 3.141592653589793; 6 | var SOLAR_MASS = 4 * PI * PI; 7 | var DAYS_PER_YEAR = 365.24; 8 | 9 | function Body(x,y,z,vx,vy,vz,mass){ 10 | this.x = x; 11 | this.y = y; 12 | this.z = z; 13 | this.vx = vx; 14 | this.vy = vy; 15 | this.vz = vz; 16 | this.mass = mass; 17 | } 18 | 19 | Body.prototype.offsetMomentum = function(px,py,pz) { 20 | this.vx = -px / SOLAR_MASS; 21 | this.vy = -py / SOLAR_MASS; 22 | this.vz = -pz / SOLAR_MASS; 23 | return this; 24 | } 25 | 26 | function Jupiter(){ 27 | return new Body( 28 | 4.84143144246472090e+00, 29 | -1.16032004402742839e+00, 30 | -1.03622044471123109e-01, 31 | 1.66007664274403694e-03 * DAYS_PER_YEAR, 32 | 7.69901118419740425e-03 * DAYS_PER_YEAR, 33 | -6.90460016972063023e-05 * DAYS_PER_YEAR, 34 | 9.54791938424326609e-04 * SOLAR_MASS 35 | ); 36 | } 37 | 38 | function Saturn(){ 39 | return new Body( 40 | 8.34336671824457987e+00, 41 | 4.12479856412430479e+00, 42 | -4.03523417114321381e-01, 43 | -2.76742510726862411e-03 * DAYS_PER_YEAR, 44 | 4.99852801234917238e-03 * DAYS_PER_YEAR, 45 | 2.30417297573763929e-05 * DAYS_PER_YEAR, 46 | 2.85885980666130812e-04 * SOLAR_MASS 47 | ); 48 | } 49 | 50 | function Uranus(){ 51 | return new Body( 52 | 1.28943695621391310e+01, 53 | -1.51111514016986312e+01, 54 | -2.23307578892655734e-01, 55 | 2.96460137564761618e-03 * DAYS_PER_YEAR, 56 | 2.37847173959480950e-03 * DAYS_PER_YEAR, 57 | -2.96589568540237556e-05 * DAYS_PER_YEAR, 58 | 4.36624404335156298e-05 * SOLAR_MASS 59 | ); 60 | } 61 | 62 | function Neptune(){ 63 | return new Body( 64 | 1.53796971148509165e+01, 65 | -2.59193146099879641e+01, 66 | 1.79258772950371181e-01, 67 | 2.68067772490389322e-03 * DAYS_PER_YEAR, 68 | 1.62824170038242295e-03 * DAYS_PER_YEAR, 69 | -9.51592254519715870e-05 * DAYS_PER_YEAR, 70 | 5.15138902046611451e-05 * SOLAR_MASS 71 | ); 72 | } 73 | 74 | function Sun(){ 75 | return new Body(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS); 76 | } 77 | 78 | 79 | function NBodySystem(bodies){ 80 | this.bodies = bodies; 81 | var px = 0.0; 82 | var py = 0.0; 83 | var pz = 0.0; 84 | var size = this.bodies.length; 85 | for (var i=0; i0){ 10 | for (var i=1; i<=prefixWidth; i++) s = " " + s; 11 | } 12 | return s; 13 | } 14 | 15 | function nsieve(m, isPrime){ 16 | var i, k, count; 17 | 18 | for (i=2; i<=m; i++) { isPrime[i] = true; } 19 | count = 0; 20 | 21 | for (i=2; i<=m; i++){ 22 | if (isPrime[i]) { 23 | for (k=i+i; k<=m; k+=i) isPrime[k] = false; 24 | count++; 25 | } 26 | } 27 | return count; 28 | } 29 | 30 | function sieve() { 31 | var sum = 0; 32 | for (var i = 1; i <= 10; i++ ) { 33 | var m = (1<> ((b << 1) & 14)); 10 | c += 3 & (bi3b >> ((b >> 2) & 14)); 11 | c += 3 & (bi3b >> ((b >> 5) & 6)); 12 | return c; 13 | 14 | /* 15 | lir4,0xE994; 9 instructions, no memory access, minimal register dependence, 6 shifts, 2 adds, 1 inline assign 16 | rlwinmr5,r3,1,28,30 17 | rlwinmr6,r3,30,28,30 18 | rlwinmr7,r3,27,29,30 19 | rlwnmr8,r4,r5,30,31 20 | rlwnmr9,r4,r6,30,31 21 | rlwnmr10,r4,r7,30,31 22 | addr3,r8,r9 23 | addr3,r3,r10 24 | */ 25 | } 26 | 27 | 28 | function TimeFunc(func) { 29 | var x, y, t; 30 | var sum = 0; 31 | for(var x=0; x<50000; x++) 32 | for(var y=0; y<256; y++) sum += func(y); 33 | return sum; 34 | } 35 | 36 | sum = TimeFunc(fast3bitlookup); 37 | 38 | var expected = 51200000; 39 | if (sum != expected) 40 | throw "ERROR: bad result: expected " + expected + " but got " + sum; 41 | -------------------------------------------------------------------------------- /LongSpider/bitops-bits-in-byte.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com) 2 | 3 | 4 | var result = 0; 5 | 6 | // 1 op = 2 assigns, 16 compare/branches, 8 ANDs, (0-8) ADDs, 8 SHLs 7 | // O(n) 8 | function bitsinbyte(b) { 9 | var m = 1, c = 0; 10 | while(m<0x100) { 11 | if(b & m) c++; 12 | m <<= 1; 13 | } 14 | return c; 15 | } 16 | 17 | function TimeFunc(func) { 18 | var x, y, t; 19 | var sum = 0; 20 | for(var x=0; x<35000; x++) 21 | for(var y=0; y<256; y++) sum += func(y); 22 | return sum; 23 | } 24 | 25 | result = TimeFunc(bitsinbyte); 26 | 27 | var expected = 35840000; 28 | if (result != expected) 29 | throw "ERROR: bad result: expected " + expected + " but got " + result; 30 | 31 | -------------------------------------------------------------------------------- /LongSpider/bitops-nsieve-bits.js: -------------------------------------------------------------------------------- 1 | // The Great Computer Language Shootout 2 | // http://shootout.alioth.debian.org 3 | // 4 | // Contributed by Ian Osgood 5 | 6 | function pad(n,width) { 7 | var s = n.toString(); 8 | while (s.length < width) s = ' ' + s; 9 | return s; 10 | } 11 | 12 | function primes(isPrime, n) { 13 | var i, count = 0, m = 10000<>5; 14 | 15 | for (i=0; i>5] & 1<<(i&31)) { 19 | for (var j=i+i; j>5] &= ~(1<<(j&31)); 21 | count++; 22 | } 23 | } 24 | 25 | function sieve() { 26 | for (var i = 4; i <= 11; i++) { 27 | var isPrime = new Array((10000<>5); 28 | primes(isPrime, i); 29 | } 30 | return isPrime; 31 | } 32 | 33 | var result = sieve(); 34 | 35 | var sum = 0; 36 | for (var i = 0; i < result.length; ++i) 37 | sum += result[i]; 38 | 39 | var expected = -116331605199501; 40 | if (sum != expected) 41 | throw "ERROR: bad result: expected " + expected + " but got " + sum; 42 | 43 | -------------------------------------------------------------------------------- /LongSpider/controlflow-recursive.js: -------------------------------------------------------------------------------- 1 | // The Computer Language Shootout 2 | // http://shootout.alioth.debian.org/ 3 | // contributed by Isaac Gouy 4 | 5 | function ack(m,n){ 6 | if (m==0) { return n+1; } 7 | if (n==0) { return ack(m-1,1); } 8 | return ack(m-1, ack(m,n-1) ); 9 | } 10 | 11 | function fib(n) { 12 | if (n < 2){ return 1; } 13 | return fib(n-2) + fib(n-1); 14 | } 15 | 16 | function tak(x,y,z) { 17 | if (y >= x) return z; 18 | return tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y)); 19 | } 20 | 21 | var result = 0; 22 | 23 | for ( var i = 3; i <= 9; i++ ) { 24 | result += ack(3,i); 25 | result += fib(17.0+i); 26 | result += tak(3*i+3,2*i+2,i+1); 27 | } 28 | 29 | var expected = 504699; 30 | if (result != expected) 31 | throw "ERROR: bad result: expected " + expected + " but got " + result; 32 | 33 | -------------------------------------------------------------------------------- /LongSpider/crypto-md5.js: -------------------------------------------------------------------------------- 1 | /* 2 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message 3 | * Digest Algorithm, as defined in RFC 1321. 4 | * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. 5 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 6 | * Distributed under the BSD License 7 | * See http://pajhome.org.uk/crypt/md5 for more info. 8 | */ 9 | 10 | /* 11 | * Configurable variables. You may need to tweak these to be compatible with 12 | * the server-side, but the defaults work in most cases. 13 | */ 14 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 15 | var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 16 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 17 | 18 | /* 19 | * These are the functions you'll usually want to call 20 | * They take string arguments and return either hex or base-64 encoded strings 21 | */ 22 | function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));} 23 | function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));} 24 | function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));} 25 | function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); } 26 | function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); } 27 | function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); } 28 | 29 | /* 30 | * Perform a simple self-test to see if the VM is working 31 | */ 32 | function md5_vm_test() 33 | { 34 | return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; 35 | } 36 | 37 | /* 38 | * Calculate the MD5 of an array of little-endian words, and a bit length 39 | */ 40 | function core_md5(x, len) 41 | { 42 | /* append padding */ 43 | x[len >> 5] |= 0x80 << ((len) % 32); 44 | x[(((len + 64) >>> 9) << 4) + 14] = len; 45 | 46 | var a = 1732584193; 47 | var b = -271733879; 48 | var c = -1732584194; 49 | var d = 271733878; 50 | 51 | for(var i = 0; i < x.length; i += 16) 52 | { 53 | var olda = a; 54 | var oldb = b; 55 | var oldc = c; 56 | var oldd = d; 57 | 58 | a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); 59 | d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); 60 | c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); 61 | b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); 62 | a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); 63 | d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); 64 | c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); 65 | b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); 66 | a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); 67 | d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); 68 | c = md5_ff(c, d, a, b, x[i+10], 17, -42063); 69 | b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); 70 | a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); 71 | d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); 72 | c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); 73 | b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); 74 | 75 | a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); 76 | d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); 77 | c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); 78 | b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); 79 | a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); 80 | d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); 81 | c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); 82 | b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); 83 | a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); 84 | d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); 85 | c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); 86 | b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); 87 | a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); 88 | d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); 89 | c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); 90 | b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); 91 | 92 | a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); 93 | d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); 94 | c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); 95 | b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); 96 | a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); 97 | d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); 98 | c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); 99 | b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); 100 | a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); 101 | d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); 102 | c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); 103 | b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); 104 | a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); 105 | d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); 106 | c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); 107 | b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); 108 | 109 | a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); 110 | d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); 111 | c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); 112 | b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); 113 | a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); 114 | d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); 115 | c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); 116 | b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); 117 | a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); 118 | d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); 119 | c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); 120 | b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); 121 | a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); 122 | d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); 123 | c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); 124 | b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); 125 | 126 | a = safe_add(a, olda); 127 | b = safe_add(b, oldb); 128 | c = safe_add(c, oldc); 129 | d = safe_add(d, oldd); 130 | } 131 | return Array(a, b, c, d); 132 | 133 | } 134 | 135 | /* 136 | * These functions implement the four basic operations the algorithm uses. 137 | */ 138 | function md5_cmn(q, a, b, x, s, t) 139 | { 140 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); 141 | } 142 | function md5_ff(a, b, c, d, x, s, t) 143 | { 144 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); 145 | } 146 | function md5_gg(a, b, c, d, x, s, t) 147 | { 148 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); 149 | } 150 | function md5_hh(a, b, c, d, x, s, t) 151 | { 152 | return md5_cmn(b ^ c ^ d, a, b, x, s, t); 153 | } 154 | function md5_ii(a, b, c, d, x, s, t) 155 | { 156 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 157 | } 158 | 159 | /* 160 | * Calculate the HMAC-MD5, of a key and some data 161 | */ 162 | function core_hmac_md5(key, data) 163 | { 164 | var bkey = str2binl(key); 165 | if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz); 166 | 167 | var ipad = Array(16), opad = Array(16); 168 | for(var i = 0; i < 16; i++) 169 | { 170 | ipad[i] = bkey[i] ^ 0x36363636; 171 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 172 | } 173 | 174 | var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); 175 | return core_md5(opad.concat(hash), 512 + 128); 176 | } 177 | 178 | /* 179 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 180 | * to work around bugs in some JS interpreters. 181 | */ 182 | function safe_add(x, y) 183 | { 184 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 185 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 186 | return (msw << 16) | (lsw & 0xFFFF); 187 | } 188 | 189 | /* 190 | * Bitwise rotate a 32-bit number to the left. 191 | */ 192 | function bit_rol(num, cnt) 193 | { 194 | return (num << cnt) | (num >>> (32 - cnt)); 195 | } 196 | 197 | /* 198 | * Convert a string to an array of little-endian words 199 | * If chrsz is ASCII, characters >255 have their hi-byte silently ignored. 200 | */ 201 | function str2binl(str) 202 | { 203 | var bin = Array(); 204 | var mask = (1 << chrsz) - 1; 205 | for(var i = 0; i < str.length * chrsz; i += chrsz) 206 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32); 207 | return bin; 208 | } 209 | 210 | /* 211 | * Convert an array of little-endian words to a string 212 | */ 213 | function binl2str(bin) 214 | { 215 | var str = ""; 216 | var mask = (1 << chrsz) - 1; 217 | for(var i = 0; i < bin.length * 32; i += chrsz) 218 | str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask); 219 | return str; 220 | } 221 | 222 | /* 223 | * Convert an array of little-endian words to a hex string. 224 | */ 225 | function binl2hex(binarray) 226 | { 227 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 228 | var str = ""; 229 | for(var i = 0; i < binarray.length * 4; i++) 230 | { 231 | str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) + 232 | hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF); 233 | } 234 | return str; 235 | } 236 | 237 | /* 238 | * Convert an array of little-endian words to a base-64 string 239 | */ 240 | function binl2b64(binarray) 241 | { 242 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 243 | var str = ""; 244 | for(var i = 0; i < binarray.length * 4; i += 3) 245 | { 246 | var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) 247 | | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) 248 | | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF); 249 | for(var j = 0; j < 4; j++) 250 | { 251 | if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; 252 | else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); 253 | } 254 | } 255 | return str; 256 | } 257 | 258 | var plainText = "Rebellious subjects, enemies to peace,\n\ 259 | Profaners of this neighbour-stained steel,--\n\ 260 | Will they not hear? What, ho! you men, you beasts,\n\ 261 | That quench the fire of your pernicious rage\n\ 262 | With purple fountains issuing from your veins,\n\ 263 | On pain of torture, from those bloody hands\n\ 264 | Throw your mistemper'd weapons to the ground,\n\ 265 | And hear the sentence of your moved prince.\n\ 266 | Three civil brawls, bred of an airy word,\n\ 267 | By thee, old Capulet, and Montague,\n\ 268 | Have thrice disturb'd the quiet of our streets,\n\ 269 | And made Verona's ancient citizens\n\ 270 | Cast by their grave beseeming ornaments,\n\ 271 | To wield old partisans, in hands as old,\n\ 272 | Canker'd with peace, to part your canker'd hate:\n\ 273 | If ever you disturb our streets again,\n\ 274 | Your lives shall pay the forfeit of the peace.\n\ 275 | For this time, all the rest depart away:\n\ 276 | You Capulet; shall go along with me:\n\ 277 | And, Montague, come you this afternoon,\n\ 278 | To know our further pleasure in this case,\n\ 279 | To old Free-town, our common judgment-place.\n\ 280 | Once more, on pain of death, all men depart." 281 | 282 | for (var i = 0; i <9; i++) { 283 | plainText += plainText; 284 | } 285 | 286 | for (var i = 0 ; i < 40; ++i) { 287 | var md5Output = hex_md5(plainText); 288 | 289 | var expected = "3dfe3a86e990dc8bf5868823e917556e"; 290 | 291 | if (md5Output != expected) 292 | throw "ERROR: bad result: expected " + expected + " but got " + md5Output; 293 | } 294 | 295 | 296 | -------------------------------------------------------------------------------- /LongSpider/crypto-sha1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined 3 | * in FIPS PUB 180-1 4 | * Version 2.1a Copyright Paul Johnston 2000 - 2002. 5 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 6 | * Distributed under the BSD License 7 | * See http://pajhome.org.uk/crypt/md5 for details. 8 | */ 9 | 10 | /* 11 | * Configurable variables. You may need to tweak these to be compatible with 12 | * the server-side, but the defaults work in most cases. 13 | */ 14 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 15 | var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 16 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 17 | 18 | /* 19 | * These are the functions you'll usually want to call 20 | * They take string arguments and return either hex or base-64 encoded strings 21 | */ 22 | function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));} 23 | function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));} 24 | function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));} 25 | function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));} 26 | function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));} 27 | function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));} 28 | 29 | /* 30 | * Perform a simple self-test to see if the VM is working 31 | */ 32 | function sha1_vm_test() 33 | { 34 | return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d"; 35 | } 36 | 37 | /* 38 | * Calculate the SHA-1 of an array of big-endian words, and a bit length 39 | */ 40 | function core_sha1(x, len) 41 | { 42 | /* append padding */ 43 | x[len >> 5] |= 0x80 << (24 - len % 32); 44 | x[((len + 64 >> 9) << 4) + 15] = len; 45 | 46 | var w = Array(80); 47 | var a = 1732584193; 48 | var b = -271733879; 49 | var c = -1732584194; 50 | var d = 271733878; 51 | var e = -1009589776; 52 | 53 | for(var i = 0; i < x.length; i += 16) 54 | { 55 | var olda = a; 56 | var oldb = b; 57 | var oldc = c; 58 | var oldd = d; 59 | var olde = e; 60 | 61 | for(var j = 0; j < 80; j++) 62 | { 63 | if(j < 16) w[j] = x[i + j]; 64 | else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); 65 | var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), 66 | safe_add(safe_add(e, w[j]), sha1_kt(j))); 67 | e = d; 68 | d = c; 69 | c = rol(b, 30); 70 | b = a; 71 | a = t; 72 | } 73 | 74 | a = safe_add(a, olda); 75 | b = safe_add(b, oldb); 76 | c = safe_add(c, oldc); 77 | d = safe_add(d, oldd); 78 | e = safe_add(e, olde); 79 | } 80 | return Array(a, b, c, d, e); 81 | 82 | } 83 | 84 | /* 85 | * Perform the appropriate triplet combination function for the current 86 | * iteration 87 | */ 88 | function sha1_ft(t, b, c, d) 89 | { 90 | if(t < 20) return (b & c) | ((~b) & d); 91 | if(t < 40) return b ^ c ^ d; 92 | if(t < 60) return (b & c) | (b & d) | (c & d); 93 | return b ^ c ^ d; 94 | } 95 | 96 | /* 97 | * Determine the appropriate additive constant for the current iteration 98 | */ 99 | function sha1_kt(t) 100 | { 101 | return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : 102 | (t < 60) ? -1894007588 : -899497514; 103 | } 104 | 105 | /* 106 | * Calculate the HMAC-SHA1 of a key and some data 107 | */ 108 | function core_hmac_sha1(key, data) 109 | { 110 | var bkey = str2binb(key); 111 | if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz); 112 | 113 | var ipad = Array(16), opad = Array(16); 114 | for(var i = 0; i < 16; i++) 115 | { 116 | ipad[i] = bkey[i] ^ 0x36363636; 117 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 118 | } 119 | 120 | var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); 121 | return core_sha1(opad.concat(hash), 512 + 160); 122 | } 123 | 124 | /* 125 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 126 | * to work around bugs in some JS interpreters. 127 | */ 128 | function safe_add(x, y) 129 | { 130 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 131 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 132 | return (msw << 16) | (lsw & 0xFFFF); 133 | } 134 | 135 | /* 136 | * Bitwise rotate a 32-bit number to the left. 137 | */ 138 | function rol(num, cnt) 139 | { 140 | return (num << cnt) | (num >>> (32 - cnt)); 141 | } 142 | 143 | /* 144 | * Convert an 8-bit or 16-bit string to an array of big-endian words 145 | * In 8-bit function, characters >255 have their hi-byte silently ignored. 146 | */ 147 | function str2binb(str) 148 | { 149 | var bin = Array(); 150 | var mask = (1 << chrsz) - 1; 151 | for(var i = 0; i < str.length * chrsz; i += chrsz) 152 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32); 153 | return bin; 154 | } 155 | 156 | /* 157 | * Convert an array of big-endian words to a string 158 | */ 159 | function binb2str(bin) 160 | { 161 | var str = ""; 162 | var mask = (1 << chrsz) - 1; 163 | for(var i = 0; i < bin.length * 32; i += chrsz) 164 | str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask); 165 | return str; 166 | } 167 | 168 | /* 169 | * Convert an array of big-endian words to a hex string. 170 | */ 171 | function binb2hex(binarray) 172 | { 173 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 174 | var str = ""; 175 | for(var i = 0; i < binarray.length * 4; i++) 176 | { 177 | str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + 178 | hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF); 179 | } 180 | return str; 181 | } 182 | 183 | /* 184 | * Convert an array of big-endian words to a base-64 string 185 | */ 186 | function binb2b64(binarray) 187 | { 188 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 189 | var str = ""; 190 | for(var i = 0; i < binarray.length * 4; i += 3) 191 | { 192 | var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16) 193 | | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 ) 194 | | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF); 195 | for(var j = 0; j < 4; j++) 196 | { 197 | if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; 198 | else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); 199 | } 200 | } 201 | return str; 202 | } 203 | 204 | 205 | var plainText = "Two households, both alike in dignity,\n\ 206 | In fair Verona, where we lay our scene,\n\ 207 | From ancient grudge break to new mutiny,\n\ 208 | Where civil blood makes civil hands unclean.\n\ 209 | From forth the fatal loins of these two foes\n\ 210 | A pair of star-cross'd lovers take their life;\n\ 211 | Whole misadventured piteous overthrows\n\ 212 | Do with their death bury their parents' strife.\n\ 213 | The fearful passage of their death-mark'd love,\n\ 214 | And the continuance of their parents' rage,\n\ 215 | Which, but their children's end, nought could remove,\n\ 216 | Is now the two hours' traffic of our stage;\n\ 217 | The which if you with patient ears attend,\n\ 218 | What here shall miss, our toil shall strive to mend."; 219 | 220 | for (var i = 0; i <12; i++) { 221 | plainText += plainText; 222 | } 223 | 224 | for (var i = 0; i < 10; ++i) { 225 | var sha1Output = hex_sha1(plainText); 226 | 227 | var expected = "716b0011ef72c5b3f12733109d82ad5d66c788fc"; 228 | if (sha1Output != expected) 229 | throw "ERROR: bad result: expected " + expected + " but got " + sha1Output; 230 | } 231 | 232 | -------------------------------------------------------------------------------- /LongSpider/date-format-tofte.js: -------------------------------------------------------------------------------- 1 | function arrayExists(array, x) { 2 | for (var i = 0; i < array.length; i++) { 3 | if (array[i] == x) return true; 4 | } 5 | return false; 6 | } 7 | 8 | Date.prototype.formatDate = function (input,time) { 9 | // formatDate : 10 | // a PHP date like function, for formatting date strings 11 | // See: http://www.php.net/date 12 | // 13 | // input : format string 14 | // time : epoch time (seconds, and optional) 15 | // 16 | // if time is not passed, formatting is based on 17 | // the current "this" date object's set time. 18 | // 19 | // supported: 20 | // a, A, B, d, D, F, g, G, h, H, i, j, l (lowercase L), L, 21 | // m, M, n, O, r, s, S, t, U, w, W, y, Y, z 22 | // 23 | // unsupported: 24 | // I (capital i), T, Z 25 | 26 | var switches = ["a", "A", "B", "d", "D", "F", "g", "G", "h", "H", 27 | "i", "j", "l", "L", "m", "M", "n", "O", "r", "s", 28 | "S", "t", "U", "w", "W", "y", "Y", "z"]; 29 | var daysLong = ["Sunday", "Monday", "Tuesday", "Wednesday", 30 | "Thursday", "Friday", "Saturday"]; 31 | var daysShort = ["Sun", "Mon", "Tue", "Wed", 32 | "Thu", "Fri", "Sat"]; 33 | var monthsShort = ["Jan", "Feb", "Mar", "Apr", 34 | "May", "Jun", "Jul", "Aug", "Sep", 35 | "Oct", "Nov", "Dec"]; 36 | var monthsLong = ["January", "February", "March", "April", 37 | "May", "June", "July", "August", "September", 38 | "October", "November", "December"]; 39 | var daysSuffix = ["st", "nd", "rd", "th", "th", "th", "th", // 1st - 7th 40 | "th", "th", "th", "th", "th", "th", "th", // 8th - 14th 41 | "th", "th", "th", "th", "th", "th", "st", // 15th - 21st 42 | "nd", "rd", "th", "th", "th", "th", "th", // 22nd - 28th 43 | "th", "th", "st"]; // 29th - 31st 44 | 45 | function a() { 46 | // Lowercase Ante meridiem and Post meridiem 47 | return self.getHours() > 11? "pm" : "am"; 48 | } 49 | function A() { 50 | // Uppercase Ante meridiem and Post meridiem 51 | return self.getHours() > 11? "PM" : "AM"; 52 | } 53 | 54 | function B(){ 55 | // Swatch internet time. code simply grabbed from ppk, 56 | // since I was feeling lazy: 57 | // http://www.xs4all.nl/~ppk/js/beat.html 58 | var off = (self.getTimezoneOffset() + 60)*60; 59 | var theSeconds = (self.getHours() * 3600) + 60 | (self.getMinutes() * 60) + 61 | self.getSeconds() + off; 62 | var beat = Math.floor(theSeconds/86.4); 63 | if (beat > 1000) beat -= 1000; 64 | if (beat < 0) beat += 1000; 65 | if ((""+beat).length == 1) beat = "00"+beat; 66 | if ((""+beat).length == 2) beat = "0"+beat; 67 | return beat; 68 | } 69 | 70 | function d() { 71 | // Day of the month, 2 digits with leading zeros 72 | return new String(self.getDate()).length == 1? 73 | "0"+self.getDate() : self.getDate(); 74 | } 75 | function D() { 76 | // A textual representation of a day, three letters 77 | return daysShort[self.getDay()]; 78 | } 79 | function F() { 80 | // A full textual representation of a month 81 | return monthsLong[self.getMonth()]; 82 | } 83 | function g() { 84 | // 12-hour format of an hour without leading zeros 85 | return self.getHours() > 12? self.getHours()-12 : self.getHours(); 86 | } 87 | function G() { 88 | // 24-hour format of an hour without leading zeros 89 | return self.getHours(); 90 | } 91 | function h() { 92 | // 12-hour format of an hour with leading zeros 93 | if (self.getHours() > 12) { 94 | var s = new String(self.getHours()-12); 95 | return s.length == 1? 96 | "0"+ (self.getHours()-12) : self.getHours()-12; 97 | } else { 98 | var s = new String(self.getHours()); 99 | return s.length == 1? 100 | "0"+self.getHours() : self.getHours(); 101 | } 102 | } 103 | function H() { 104 | // 24-hour format of an hour with leading zeros 105 | return new String(self.getHours()).length == 1? 106 | "0"+self.getHours() : self.getHours(); 107 | } 108 | function i() { 109 | // Minutes with leading zeros 110 | return new String(self.getMinutes()).length == 1? 111 | "0"+self.getMinutes() : self.getMinutes(); 112 | } 113 | function j() { 114 | // Day of the month without leading zeros 115 | return self.getDate(); 116 | } 117 | function l() { 118 | // A full textual representation of the day of the week 119 | return daysLong[self.getDay()]; 120 | } 121 | function L() { 122 | // leap year or not. 1 if leap year, 0 if not. 123 | // the logic should match iso's 8601 standard. 124 | var y_ = Y(); 125 | if ( 126 | (y_ % 4 == 0 && y_ % 100 != 0) || 127 | (y_ % 4 == 0 && y_ % 100 == 0 && y_ % 400 == 0) 128 | ) { 129 | return 1; 130 | } else { 131 | return 0; 132 | } 133 | } 134 | function m() { 135 | // Numeric representation of a month, with leading zeros 136 | return self.getMonth() < 9? 137 | "0"+(self.getMonth()+1) : 138 | self.getMonth()+1; 139 | } 140 | function M() { 141 | // A short textual representation of a month, three letters 142 | return monthsShort[self.getMonth()]; 143 | } 144 | function n() { 145 | // Numeric representation of a month, without leading zeros 146 | return self.getMonth()+1; 147 | } 148 | function O() { 149 | // Difference to Greenwich time (GMT) in hours 150 | var os = Math.abs(self.getTimezoneOffset()); 151 | var h = ""+Math.floor(os/60); 152 | var m = ""+(os%60); 153 | h.length == 1? h = "0"+h:1; 154 | m.length == 1? m = "0"+m:1; 155 | return self.getTimezoneOffset() < 0 ? "+"+h+m : "-"+h+m; 156 | } 157 | function r() { 158 | // RFC 822 formatted date 159 | var r; // result 160 | // Thu , 21 Dec 2000 161 | r = D() + ", " + j() + " " + M() + " " + Y() + 162 | // 16 : 01 : 07 +0200 163 | " " + H() + ":" + i() + ":" + s() + " " + O(); 164 | return r; 165 | } 166 | function S() { 167 | // English ordinal suffix for the day of the month, 2 characters 168 | return daysSuffix[self.getDate()-1]; 169 | } 170 | function s() { 171 | // Seconds, with leading zeros 172 | return new String(self.getSeconds()).length == 1? 173 | "0"+self.getSeconds() : self.getSeconds(); 174 | } 175 | function t() { 176 | 177 | // thanks to Matt Bannon for some much needed code-fixes here! 178 | var daysinmonths = [null,31,28,31,30,31,30,31,31,30,31,30,31]; 179 | if (L()==1 && n()==2) return 29; // leap day 180 | return daysinmonths[n()]; 181 | } 182 | function U() { 183 | // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 184 | return Math.round(self.getTime()/1000); 185 | } 186 | function W() { 187 | // Weeknumber, as per ISO specification: 188 | // http://www.cl.cam.ac.uk/~mgk25/iso-time.html 189 | 190 | // if the day is three days before newyears eve, 191 | // there's a chance it's "week 1" of next year. 192 | // here we check for that. 193 | var beforeNY = 364+L() - z(); 194 | var afterNY = z(); 195 | var weekday = w()!=0?w()-1:6; // makes sunday (0), into 6. 196 | if (beforeNY <= 2 && weekday <= 2-beforeNY) { 197 | return 1; 198 | } 199 | // similarly, if the day is within threedays of newyears 200 | // there's a chance it belongs in the old year. 201 | var ny = new Date("January 1 " + Y() + " 00:00:00"); 202 | var nyDay = ny.getDay()!=0?ny.getDay()-1:6; 203 | if ( 204 | (afterNY <= 2) && 205 | (nyDay >=4) && 206 | (afterNY >= (6-nyDay)) 207 | ) { 208 | // Since I'm not sure we can just always return 53, 209 | // i call the function here again, using the last day 210 | // of the previous year, as the date, and then just 211 | // return that week. 212 | var prevNY = new Date("December 31 " + (Y()-1) + " 00:00:00"); 213 | return prevNY.formatDate("W"); 214 | } 215 | 216 | // week 1, is the week that has the first thursday in it. 217 | // note that this value is not zero index. 218 | if (nyDay <= 3) { 219 | // first day of the year fell on a thursday, or earlier. 220 | return 1 + Math.floor( ( z() + nyDay ) / 7 ); 221 | } else { 222 | // first day of the year fell on a friday, or later. 223 | return 1 + Math.floor( ( z() - ( 7 - nyDay ) ) / 7 ); 224 | } 225 | } 226 | function w() { 227 | // Numeric representation of the day of the week 228 | return self.getDay(); 229 | } 230 | 231 | function Y() { 232 | // A full numeric representation of a year, 4 digits 233 | 234 | // we first check, if getFullYear is supported. if it 235 | // is, we just use that. ppks code is nice, but wont 236 | // work with dates outside 1900-2038, or something like that 237 | if (self.getFullYear) { 238 | var newDate = new Date("January 1 2001 00:00:00 +0000"); 239 | var x = newDate .getFullYear(); 240 | if (x == 2001) { 241 | // i trust the method now 242 | return self.getFullYear(); 243 | } 244 | } 245 | // else, do this: 246 | // codes thanks to ppk: 247 | // http://www.xs4all.nl/~ppk/js/introdate.html 248 | var x = self.getYear(); 249 | var y = x % 100; 250 | y += (y < 38) ? 2000 : 1900; 251 | return y; 252 | } 253 | function y() { 254 | // A two-digit representation of a year 255 | var y = Y()+""; 256 | return y.substring(y.length-2,y.length); 257 | } 258 | function z() { 259 | // The day of the year, zero indexed! 0 through 366 260 | var t = new Date("January 1 " + Y() + " 00:00:00"); 261 | var diff = self.getTime() - t.getTime(); 262 | return Math.floor(diff/1000/60/60/24); 263 | } 264 | 265 | var self = this; 266 | if (time) { 267 | // save time 268 | var prevTime = self.getTime(); 269 | self.setTime(time); 270 | } 271 | 272 | var ia = input.split(""); 273 | var ij = 0; 274 | while (ia[ij]) { 275 | if (ia[ij] == "\\") { 276 | // this is our way of allowing users to escape stuff 277 | ia.splice(ij,1); 278 | } else { 279 | if (arrayExists(switches,ia[ij])) { 280 | ia[ij] = eval(ia[ij] + "()"); 281 | } 282 | } 283 | ij++; 284 | } 285 | // reset time, back to what it was 286 | if (prevTime) { 287 | self.setTime(prevTime); 288 | } 289 | return ia.join(""); 290 | } 291 | 292 | var date = new Date("1/1/2007 1:11:11"); 293 | 294 | for (i = 0; i < 60000; ++i) { 295 | var shortFormat = date.formatDate("Y-m-d"); 296 | var longFormat = date.formatDate("l, F d, Y g:i:s A"); 297 | date.setTime(date.getTime() + 84266956); 298 | } 299 | 300 | // FIXME: Find a way to validate this test. 301 | // https://bugs.webkit.org/show_bug.cgi?id=114849 302 | -------------------------------------------------------------------------------- /LongSpider/math-cordic.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Rich Moore. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /////. Start CORDIC 27 | 28 | var AG_CONST = 0.6072529350; 29 | 30 | function FIXED(X) 31 | { 32 | return X * 65536.0; 33 | } 34 | 35 | function FLOAT(X) 36 | { 37 | return X / 65536.0; 38 | } 39 | 40 | function DEG2RAD(X) 41 | { 42 | return 0.017453 * (X); 43 | } 44 | 45 | var Angles = [ 46 | FIXED(45.0), FIXED(26.565), FIXED(14.0362), FIXED(7.12502), 47 | FIXED(3.57633), FIXED(1.78991), FIXED(0.895174), FIXED(0.447614), 48 | FIXED(0.223811), FIXED(0.111906), FIXED(0.055953), 49 | FIXED(0.027977) 50 | ]; 51 | 52 | var Target = 28.027; 53 | 54 | function cordicsincos(Target) { 55 | var X; 56 | var Y; 57 | var TargetAngle; 58 | var CurrAngle; 59 | var Step; 60 | 61 | X = FIXED(AG_CONST); /* AG_CONST * cos(0) */ 62 | Y = 0; /* AG_CONST * sin(0) */ 63 | 64 | TargetAngle = FIXED(Target); 65 | CurrAngle = 0; 66 | for (Step = 0; Step < 12; Step++) { 67 | var NewX; 68 | if (TargetAngle > CurrAngle) { 69 | NewX = X - (Y >> Step); 70 | Y = (X >> Step) + Y; 71 | X = NewX; 72 | CurrAngle += Angles[Step]; 73 | } else { 74 | NewX = X + (Y >> Step); 75 | Y = -(X >> Step) + Y; 76 | X = NewX; 77 | CurrAngle -= Angles[Step]; 78 | } 79 | } 80 | 81 | return FLOAT(X) * FLOAT(Y); 82 | } 83 | 84 | ///// End CORDIC 85 | 86 | var total = 0; 87 | 88 | function cordic( runs ) { 89 | var start = new Date(); 90 | 91 | for ( var i = 0 ; i < runs ; i++ ) { 92 | total += cordicsincos(Target); 93 | } 94 | 95 | var end = new Date(); 96 | 97 | return end.getTime() - start.getTime(); 98 | } 99 | 100 | cordic(13000000); 101 | 102 | var expected = 5388536.644120298; 103 | 104 | if (total != expected) 105 | throw "ERROR: bad result: expected " + expected + " but got " + total; 106 | 107 | -------------------------------------------------------------------------------- /LongSpider/math-partial-sums.js: -------------------------------------------------------------------------------- 1 | // The Computer Language Shootout 2 | // http://shootout.alioth.debian.org/ 3 | // contributed by Isaac Gouy 4 | 5 | function partial(n){ 6 | var a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 0.0; 7 | var twothirds = 2.0/3.0; 8 | var alt = -1.0; 9 | var k2 = k3 = sk = ck = 0.0; 10 | 11 | for (var k = 1; k <= n; k++){ 12 | k2 = k*k; 13 | k3 = k2*k; 14 | sk = Math.sin(k); 15 | ck = Math.cos(k); 16 | alt = -alt; 17 | 18 | a1 += Math.pow(twothirds,k-1); 19 | a2 += Math.pow(k,-0.5); 20 | a3 += 1.0/(k*(k+1.0)); 21 | a4 += 1.0/(k3 * sk*sk); 22 | a5 += 1.0/(k3 * ck*ck); 23 | a6 += 1.0/k; 24 | a7 += 1.0/k2; 25 | a8 += alt/k; 26 | a9 += alt/(2*k -1); 27 | } 28 | 29 | // NOTE: We don't try to validate anything from pow(), sin() or cos() because those aren't 30 | // well-specified in ECMAScript. 31 | return a6 + a7 + a8 + a9; 32 | } 33 | 34 | var total = 0; 35 | 36 | for (var i = 1024; i <= 2097152; i *= 2) { 37 | total += partial(i); 38 | } 39 | 40 | var expected = 173.3312765300306; 41 | 42 | if (total != expected) { 43 | throw "ERROR: bad result: expected " + expected + " but got " + total; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /LongSpider/math-spectral-norm.js: -------------------------------------------------------------------------------- 1 | // The Great Computer Language Shootout 2 | // http://shootout.alioth.debian.org/ 3 | // 4 | // contributed by Ian Osgood 5 | 6 | function A(i,j) { 7 | return 1/((i+j)*(i+j+1)/2+i+1); 8 | } 9 | 10 | function Au(u,v) { 11 | for (var i=0; i (original author) 23 | * Samuel Sieb 24 | * 25 | * Alternatively, the contents of this file may be used under the terms of 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28 | * in which case the provisions of the GPL or the LGPL are applicable instead 29 | * of those above. If you wish to allow use of your version of this file only 30 | * under the terms of either the GPL or the LGPL, and not to allow others to 31 | * use your version of this file under the terms of the MPL, indicate your 32 | * decision by deleting the provisions above and replace them with the notice 33 | * and other provisions required by the GPL or the LGPL. If you do not delete 34 | * the provisions above, a recipient may use your version of this file under 35 | * the terms of any one of the MPL, the GPL or the LGPL. 36 | * 37 | * ***** END LICENSE BLOCK ***** */ 38 | 39 | // From: http://lxr.mozilla.org/mozilla/source/extensions/xml-rpc/src/nsXmlRpcClient.js#956 40 | 41 | /* Convert data (an array of integers) to a Base64 string. */ 42 | var toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; 43 | var base64Pad = '='; 44 | 45 | function toBase64(data) { 46 | var result = ''; 47 | var length = data.length; 48 | var i; 49 | // Convert every three bytes to 4 ascii characters. 50 | for (i = 0; i < (length - 2); i += 3) { 51 | result += toBase64Table[data.charCodeAt(i) >> 2]; 52 | result += toBase64Table[((data.charCodeAt(i) & 0x03) << 4) + (data.charCodeAt(i+1) >> 4)]; 53 | result += toBase64Table[((data.charCodeAt(i+1) & 0x0f) << 2) + (data.charCodeAt(i+2) >> 6)]; 54 | result += toBase64Table[data.charCodeAt(i+2) & 0x3f]; 55 | } 56 | 57 | // Convert the remaining 1 or 2 bytes, pad out to 4 characters. 58 | if (length%3) { 59 | i = length - (length%3); 60 | result += toBase64Table[data.charCodeAt(i) >> 2]; 61 | if ((length%3) == 2) { 62 | result += toBase64Table[((data.charCodeAt(i) & 0x03) << 4) + (data.charCodeAt(i+1) >> 4)]; 63 | result += toBase64Table[(data.charCodeAt(i+1) & 0x0f) << 2]; 64 | result += base64Pad; 65 | } else { 66 | result += toBase64Table[(data.charCodeAt(i) & 0x03) << 4]; 67 | result += base64Pad + base64Pad; 68 | } 69 | } 70 | 71 | return result; 72 | } 73 | 74 | /* Convert Base64 data to a string */ 75 | var toBinaryTable = [ 76 | -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, 77 | -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, 78 | -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63, 79 | 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1, 80 | -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14, 81 | 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1, 82 | -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40, 83 | 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1 84 | ]; 85 | 86 | function base64ToString(data) { 87 | var result = ''; 88 | var leftbits = 0; // number of bits decoded, but yet to be appended 89 | var leftdata = 0; // bits decoded, but yet to be appended 90 | 91 | // Convert one by one. 92 | for (var i = 0; i < data.length; i++) { 93 | var c = toBinaryTable[data.charCodeAt(i) & 0x7f]; 94 | var padding = (data.charCodeAt(i) == base64Pad.charCodeAt(0)); 95 | // Skip illegal characters and whitespace 96 | if (c == -1) continue; 97 | 98 | // Collect data into leftdata, update bitcount 99 | leftdata = (leftdata << 6) | c; 100 | leftbits += 6; 101 | 102 | // If we have 8 or more bits, append 8 bits to the result 103 | if (leftbits >= 8) { 104 | leftbits -= 8; 105 | // Append if not padding. 106 | if (!padding) 107 | result += String.fromCharCode((leftdata >> leftbits) & 0xff); 108 | leftdata &= (1 << leftbits) - 1; 109 | } 110 | } 111 | 112 | // If there are any bits left, the base64 string was corrupted 113 | if (leftbits) 114 | throw Components.Exception('Corrupted base64 string'); 115 | 116 | return result; 117 | } 118 | 119 | var str = ""; 120 | 121 | for ( var i = 0; i < 8192; i++ ) 122 | str += String.fromCharCode( (25 * Math.random()) + 97 ); 123 | 124 | for ( var i = 8192; i <= 2097152; i *= 2 ) { 125 | 126 | var base64; 127 | 128 | base64 = toBase64(str); 129 | var encoded = base64ToString(base64); 130 | if (encoded != str) 131 | throw "ERROR: bad result: expected " + str + " but got " + encoded; 132 | 133 | // Double the string 134 | str += str; 135 | } 136 | 137 | toBinaryTable = null; 138 | -------------------------------------------------------------------------------- /LongSpider/string-fasta.js: -------------------------------------------------------------------------------- 1 | // The Great Computer Language Shootout 2 | // http://shootout.alioth.debian.org 3 | // 4 | // Contributed by Ian Osgood 5 | 6 | var last = 42, A = 3877, C = 29573, M = 139968; 7 | 8 | function rand(max) { 9 | last = (last * A + C) % M; 10 | return max * last / M; 11 | } 12 | 13 | var ALU = 14 | "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + 15 | "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + 16 | "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + 17 | "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" + 18 | "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" + 19 | "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" + 20 | "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; 21 | 22 | var IUB = { 23 | a:0.27, c:0.12, g:0.12, t:0.27, 24 | B:0.02, D:0.02, H:0.02, K:0.02, 25 | M:0.02, N:0.02, R:0.02, S:0.02, 26 | V:0.02, W:0.02, Y:0.02 27 | } 28 | 29 | var HomoSap = { 30 | a: 0.3029549426680, 31 | c: 0.1979883004921, 32 | g: 0.1975473066391, 33 | t: 0.3015094502008 34 | } 35 | 36 | function makeCumulative(table) { 37 | var last = null; 38 | for (var c in table) { 39 | if (last) table[c] += table[last]; 40 | last = c; 41 | } 42 | } 43 | 44 | function fastaRepeat(n, seq) { 45 | var seqi = 0, lenOut = 60; 46 | while (n>0) { 47 | if (n0) { 64 | if (n x * 2); 9 | } 10 | } 11 | 12 | f(); 13 | -------------------------------------------------------------------------------- /MicroBench/bound-call-00-args.js: -------------------------------------------------------------------------------- 1 | function go() { 2 | function target() {} 3 | 4 | const bound = target.bind(null); 5 | for (let i = 0; i < 50_000_000; ++i) { 6 | bound(); 7 | } 8 | } 9 | 10 | go(); 11 | -------------------------------------------------------------------------------- /MicroBench/bound-call-04-args.js: -------------------------------------------------------------------------------- 1 | function go() { 2 | function target() {} 3 | 4 | const bound = target.bind(null, 1, 2, 3, 4); 5 | for (let i = 0; i < 50_000_000; ++i) { 6 | bound(); 7 | } 8 | } 9 | 10 | go(); 11 | -------------------------------------------------------------------------------- /MicroBench/bound-call-16-args.js: -------------------------------------------------------------------------------- 1 | function go() { 2 | function target() {} 3 | 4 | const bound = target.bind( 5 | null, 6 | 1, 7 | 2, 8 | 3, 9 | 4, 10 | 5, 11 | 6, 12 | 7, 13 | 8, 14 | 9, 15 | 10, 16 | 11, 17 | 12, 18 | 13, 19 | 14, 20 | 15, 21 | 16, 22 | ); 23 | for (let i = 0; i < 50_000_000; ++i) { 24 | bound(); 25 | } 26 | } 27 | 28 | go(); 29 | -------------------------------------------------------------------------------- /MicroBench/call-00-args.js: -------------------------------------------------------------------------------- 1 | function foo(f) { 2 | for (let i = 0; i < 50_000_000; ++i) 3 | f(); 4 | } 5 | 6 | foo(function() {}) 7 | -------------------------------------------------------------------------------- /MicroBench/call-01-args.js: -------------------------------------------------------------------------------- 1 | function foo(f) { 2 | for (let i = 0; i < 50_000_000; ++i) 3 | f(1); 4 | } 5 | 6 | foo(function() {}) 7 | -------------------------------------------------------------------------------- /MicroBench/call-02-args.js: -------------------------------------------------------------------------------- 1 | function foo(f) { 2 | for (let i = 0; i < 50_000_000; ++i) 3 | f(1, 2); 4 | } 5 | 6 | foo(function() {}) 7 | -------------------------------------------------------------------------------- /MicroBench/call-03-args.js: -------------------------------------------------------------------------------- 1 | function foo(f) { 2 | for (let i = 0; i < 50_000_000; ++i) 3 | f(1, 2, 3); 4 | } 5 | 6 | foo(function() {}) 7 | -------------------------------------------------------------------------------- /MicroBench/call-04-args.js: -------------------------------------------------------------------------------- 1 | function foo(f) { 2 | for (let i = 0; i < 50_000_000; ++i) 3 | f(1, 2, 3, 4); 4 | } 5 | 6 | foo(function() {}) 7 | -------------------------------------------------------------------------------- /MicroBench/call-16-args.js: -------------------------------------------------------------------------------- 1 | function foo(f) { 2 | for (let i = 0; i < 50_000_000; ++i) 3 | f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); 4 | } 5 | 6 | foo(function() {}) 7 | -------------------------------------------------------------------------------- /MicroBench/call-32-args.js: -------------------------------------------------------------------------------- 1 | function foo(f) { 2 | for (let i = 0; i < 50_000_000; ++i) 3 | f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32); 4 | } 5 | 6 | foo(function() {}) 7 | -------------------------------------------------------------------------------- /MicroBench/for-in-indexed-properties.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | const arr = new Array(1_000_000).fill('x'); 3 | let counter = 0; 4 | for (let i = 0; i < 8; ++i) { 5 | for (let _ in arr) { 6 | counter++; 7 | } 8 | } 9 | return counter; 10 | } 11 | 12 | let counter = foo(); 13 | console.log(counter); 14 | -------------------------------------------------------------------------------- /MicroBench/for-in-named-properties.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | let o = {} 3 | for (let i = 0; i < 128; ++i) 4 | o[String.fromCharCode(i)] = "OK"; 5 | let counter = 0; 6 | for (let i = 0; i < 250_000; ++i) { 7 | for (let _ in o) { 8 | counter++; 9 | } 10 | } 11 | return counter; 12 | } 13 | 14 | let counter = foo(); 15 | console.log(counter); 16 | -------------------------------------------------------------------------------- /MicroBench/for-of.js: -------------------------------------------------------------------------------- 1 | const arr = new Array(10_000_000); 2 | let counter = 0; 3 | for (let _ of arr) { 4 | counter++; 5 | } 6 | -------------------------------------------------------------------------------- /MicroBench/object-keys.js: -------------------------------------------------------------------------------- 1 | function f() { 2 | var object = {}; 3 | for (let i = 0; i < 100; i++) object["k" + i] = i; 4 | 5 | for (var i = 0; i < 500_000; i++) { 6 | Object.keys(object); 7 | } 8 | } 9 | 10 | f(); 11 | -------------------------------------------------------------------------------- /MicroBench/pic-get-own.js: -------------------------------------------------------------------------------- 1 | function go() { 2 | function foo(o) { 3 | o.kek; 4 | } 5 | 6 | let a = { kek: 1 }; 7 | let b = { a: 1, kek: 1 }; 8 | let c = { a: 1, b: 1, kek: 1 }; 9 | let d = { a: 1, b: 1, c: 1, kek: 1 }; 10 | 11 | for (let i = 0; i < 10_000_000; ++i) { 12 | foo(a); 13 | foo(b); 14 | foo(c); 15 | foo(d); 16 | } 17 | } 18 | 19 | go(); 20 | -------------------------------------------------------------------------------- /MicroBench/pic-get-pchain.js: -------------------------------------------------------------------------------- 1 | function go() { 2 | function foo(o) { 3 | o.kek; 4 | } 5 | 6 | let pa = { kek: 1 }; 7 | let pb = { a: 1, kek: 1 }; 8 | let pc = { a: 1, b: 1, kek: 1 }; 9 | let pd = { a: 1, b: 1, c: 1, kek: 1 }; 10 | let pe = { a: 1, b: 1, c: 1, d: 1, kek: 1 }; 11 | 12 | let a = { __proto__: pa }; 13 | let b = { __proto__: pb }; 14 | let c = { __proto__: pc }; 15 | let d = { __proto__: pd }; 16 | let e = { __proto__: pe }; 17 | 18 | for (let i = 0; i < 10_000_000; ++i) { 19 | foo(a); 20 | foo(b); 21 | foo(c); 22 | foo(d); 23 | } 24 | } 25 | 26 | go(); 27 | -------------------------------------------------------------------------------- /MicroBench/pic-put-own.js: -------------------------------------------------------------------------------- 1 | function go() { 2 | function foo(o) { 3 | o.kek = 3; 4 | } 5 | 6 | let a = { kek: 1 }; 7 | let b = { a: 1, kek: 1 }; 8 | let c = { a: 1, b: 1, kek: 1 }; 9 | let d = { a: 1, b: 1, c: 1, kek: 1 }; 10 | 11 | for (let i = 0; i < 10_000_000; ++i) { 12 | foo(a); 13 | foo(b); 14 | foo(c); 15 | foo(d); 16 | } 17 | } 18 | 19 | go(); 20 | -------------------------------------------------------------------------------- /MicroBench/pic-put-pchain.js: -------------------------------------------------------------------------------- 1 | function go() { 2 | function foo(o) { 3 | o.kek = 3; 4 | } 5 | 6 | let pa = { set kek(v) {} }; 7 | let pb = { a: 1, set kek(v) {} }; 8 | let pc = { a: 1, b: 1, set kek(v) {} }; 9 | let pd = { a: 1, b: 1, c: 1, set kek(v) {} }; 10 | let pe = { a: 1, b: 1, c: 1, d: 1, set kek(v) {} }; 11 | 12 | let a = { __proto__: pa }; 13 | let b = { __proto__: pb }; 14 | let c = { __proto__: pc }; 15 | let d = { __proto__: pd }; 16 | let e = { __proto__: pe }; 17 | 18 | for (let i = 0; i < 10_000_000; ++i) { 19 | foo(a); 20 | foo(b); 21 | foo(c); 22 | foo(d); 23 | } 24 | } 25 | 26 | go(); 27 | -------------------------------------------------------------------------------- /MicroBench/setter-in-prototype-chain.js: -------------------------------------------------------------------------------- 1 | var setterCalls = 0; 2 | 3 | let o = {}; 4 | o.__proto__ = {}; 5 | o.__proto__.__proto__ = {}; 6 | o.__proto__.__proto__.__proto__ = { 7 | set go(v) { 8 | setterCalls += v; 9 | }, 10 | }; 11 | function moo(o) { 12 | for (let i = 0; i < 50_000_000; ++i) { 13 | o.go = 1; 14 | } 15 | } 16 | moo(o); 17 | 18 | console.log(setterCalls); 19 | -------------------------------------------------------------------------------- /MicroBench/strictly-equals-object.js: -------------------------------------------------------------------------------- 1 | let a = {}; 2 | let b = a; 3 | for (let i = 0; i < 100_000_000; ++i) { 4 | if (a === b) 5 | continue; 6 | } 7 | -------------------------------------------------------------------------------- /Octane/code-load.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LadybirdBrowser/js-benchmarks/daba05ec54a9c62c8bd97110d81ad668b08c689f/Octane/code-load.js -------------------------------------------------------------------------------- /SunSpider/3d-cube.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | // 3D Cube Rotation 36 | // http://www.speich.net/computer/moztesting/3d.htm 37 | // Created by Simon Speich 38 | 39 | var Q = new Array(); 40 | var MTrans = new Array(); // transformation matrix 41 | var MQube = new Array(); // position information of qube 42 | var I = new Array(); // entity matrix 43 | var Origin = new Object(); 44 | var Testing = new Object(); 45 | var LoopTimer; 46 | 47 | var validation = { 48 | 20: 2889.0000000000045, 49 | 40: 2889.0000000000055, 50 | 80: 2889.000000000005, 51 | 160: 2889.0000000000055 52 | }; 53 | 54 | var DisplArea = new Object(); 55 | DisplArea.Width = 300; 56 | DisplArea.Height = 300; 57 | 58 | function DrawLine(From, To) { 59 | var x1 = From.V[0]; 60 | var x2 = To.V[0]; 61 | var y1 = From.V[1]; 62 | var y2 = To.V[1]; 63 | var dx = Math.abs(x2 - x1); 64 | var dy = Math.abs(y2 - y1); 65 | var x = x1; 66 | var y = y1; 67 | var IncX1, IncY1; 68 | var IncX2, IncY2; 69 | var Den; 70 | var Num; 71 | var NumAdd; 72 | var NumPix; 73 | 74 | if (x2 >= x1) { IncX1 = 1; IncX2 = 1; } 75 | else { IncX1 = -1; IncX2 = -1; } 76 | if (y2 >= y1) { IncY1 = 1; IncY2 = 1; } 77 | else { IncY1 = -1; IncY2 = -1; } 78 | if (dx >= dy) { 79 | IncX1 = 0; 80 | IncY2 = 0; 81 | Den = dx; 82 | Num = dx / 2; 83 | NumAdd = dy; 84 | NumPix = dx; 85 | } 86 | else { 87 | IncX2 = 0; 88 | IncY1 = 0; 89 | Den = dy; 90 | Num = dy / 2; 91 | NumAdd = dx; 92 | NumPix = dy; 93 | } 94 | 95 | NumPix = Math.round(Q.LastPx + NumPix); 96 | 97 | var i = Q.LastPx; 98 | for (; i < NumPix; i++) { 99 | Num += NumAdd; 100 | if (Num >= Den) { 101 | Num -= Den; 102 | x += IncX1; 103 | y += IncY1; 104 | } 105 | x += IncX2; 106 | y += IncY2; 107 | } 108 | Q.LastPx = NumPix; 109 | } 110 | 111 | function CalcCross(V0, V1) { 112 | var Cross = new Array(); 113 | Cross[0] = V0[1]*V1[2] - V0[2]*V1[1]; 114 | Cross[1] = V0[2]*V1[0] - V0[0]*V1[2]; 115 | Cross[2] = V0[0]*V1[1] - V0[1]*V1[0]; 116 | return Cross; 117 | } 118 | 119 | function CalcNormal(V0, V1, V2) { 120 | var A = new Array(); var B = new Array(); 121 | for (var i = 0; i < 3; i++) { 122 | A[i] = V0[i] - V1[i]; 123 | B[i] = V2[i] - V1[i]; 124 | } 125 | A = CalcCross(A, B); 126 | var Length = Math.sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]); 127 | for (var i = 0; i < 3; i++) A[i] = A[i] / Length; 128 | A[3] = 1; 129 | return A; 130 | } 131 | 132 | function CreateP(X,Y,Z) { 133 | this.V = [X,Y,Z,1]; 134 | } 135 | 136 | // multiplies two matrices 137 | function MMulti(M1, M2) { 138 | var M = [[],[],[],[]]; 139 | var i = 0; 140 | var j = 0; 141 | for (; i < 4; i++) { 142 | j = 0; 143 | for (; j < 4; j++) M[i][j] = M1[i][0] * M2[0][j] + M1[i][1] * M2[1][j] + M1[i][2] * M2[2][j] + M1[i][3] * M2[3][j]; 144 | } 145 | return M; 146 | } 147 | 148 | //multiplies matrix with vector 149 | function VMulti(M, V) { 150 | var Vect = new Array(); 151 | var i = 0; 152 | for (;i < 4; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2] + M[i][3] * V[3]; 153 | return Vect; 154 | } 155 | 156 | function VMulti2(M, V) { 157 | var Vect = new Array(); 158 | var i = 0; 159 | for (;i < 3; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2]; 160 | return Vect; 161 | } 162 | 163 | // add to matrices 164 | function MAdd(M1, M2) { 165 | var M = [[],[],[],[]]; 166 | var i = 0; 167 | var j = 0; 168 | for (; i < 4; i++) { 169 | j = 0; 170 | for (; j < 4; j++) M[i][j] = M1[i][j] + M2[i][j]; 171 | } 172 | return M; 173 | } 174 | 175 | function Translate(M, Dx, Dy, Dz) { 176 | var T = [ 177 | [1,0,0,Dx], 178 | [0,1,0,Dy], 179 | [0,0,1,Dz], 180 | [0,0,0,1] 181 | ]; 182 | return MMulti(T, M); 183 | } 184 | 185 | function RotateX(M, Phi) { 186 | var a = Phi; 187 | a *= Math.PI / 180; 188 | var Cos = Math.cos(a); 189 | var Sin = Math.sin(a); 190 | var R = [ 191 | [1,0,0,0], 192 | [0,Cos,-Sin,0], 193 | [0,Sin,Cos,0], 194 | [0,0,0,1] 195 | ]; 196 | return MMulti(R, M); 197 | } 198 | 199 | function RotateY(M, Phi) { 200 | var a = Phi; 201 | a *= Math.PI / 180; 202 | var Cos = Math.cos(a); 203 | var Sin = Math.sin(a); 204 | var R = [ 205 | [Cos,0,Sin,0], 206 | [0,1,0,0], 207 | [-Sin,0,Cos,0], 208 | [0,0,0,1] 209 | ]; 210 | return MMulti(R, M); 211 | } 212 | 213 | function RotateZ(M, Phi) { 214 | var a = Phi; 215 | a *= Math.PI / 180; 216 | var Cos = Math.cos(a); 217 | var Sin = Math.sin(a); 218 | var R = [ 219 | [Cos,-Sin,0,0], 220 | [Sin,Cos,0,0], 221 | [0,0,1,0], 222 | [0,0,0,1] 223 | ]; 224 | return MMulti(R, M); 225 | } 226 | 227 | function DrawQube() { 228 | // calc current normals 229 | var CurN = new Array(); 230 | var i = 5; 231 | Q.LastPx = 0; 232 | for (; i > -1; i--) CurN[i] = VMulti2(MQube, Q.Normal[i]); 233 | if (CurN[0][2] < 0) { 234 | if (!Q.Line[0]) { DrawLine(Q[0], Q[1]); Q.Line[0] = true; }; 235 | if (!Q.Line[1]) { DrawLine(Q[1], Q[2]); Q.Line[1] = true; }; 236 | if (!Q.Line[2]) { DrawLine(Q[2], Q[3]); Q.Line[2] = true; }; 237 | if (!Q.Line[3]) { DrawLine(Q[3], Q[0]); Q.Line[3] = true; }; 238 | } 239 | if (CurN[1][2] < 0) { 240 | if (!Q.Line[2]) { DrawLine(Q[3], Q[2]); Q.Line[2] = true; }; 241 | if (!Q.Line[9]) { DrawLine(Q[2], Q[6]); Q.Line[9] = true; }; 242 | if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; }; 243 | if (!Q.Line[10]) { DrawLine(Q[7], Q[3]); Q.Line[10] = true; }; 244 | } 245 | if (CurN[2][2] < 0) { 246 | if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; }; 247 | if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; }; 248 | if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; }; 249 | if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; }; 250 | } 251 | if (CurN[3][2] < 0) { 252 | if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; }; 253 | if (!Q.Line[8]) { DrawLine(Q[5], Q[1]); Q.Line[8] = true; }; 254 | if (!Q.Line[0]) { DrawLine(Q[1], Q[0]); Q.Line[0] = true; }; 255 | if (!Q.Line[11]) { DrawLine(Q[0], Q[4]); Q.Line[11] = true; }; 256 | } 257 | if (CurN[4][2] < 0) { 258 | if (!Q.Line[11]) { DrawLine(Q[4], Q[0]); Q.Line[11] = true; }; 259 | if (!Q.Line[3]) { DrawLine(Q[0], Q[3]); Q.Line[3] = true; }; 260 | if (!Q.Line[10]) { DrawLine(Q[3], Q[7]); Q.Line[10] = true; }; 261 | if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; }; 262 | } 263 | if (CurN[5][2] < 0) { 264 | if (!Q.Line[8]) { DrawLine(Q[1], Q[5]); Q.Line[8] = true; }; 265 | if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; }; 266 | if (!Q.Line[9]) { DrawLine(Q[6], Q[2]); Q.Line[9] = true; }; 267 | if (!Q.Line[1]) { DrawLine(Q[2], Q[1]); Q.Line[1] = true; }; 268 | } 269 | Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false]; 270 | Q.LastPx = 0; 271 | } 272 | 273 | function Loop() { 274 | if (Testing.LoopCount > Testing.LoopMax) return; 275 | var TestingStr = String(Testing.LoopCount); 276 | while (TestingStr.length < 3) TestingStr = "0" + TestingStr; 277 | MTrans = Translate(I, -Q[8].V[0], -Q[8].V[1], -Q[8].V[2]); 278 | MTrans = RotateX(MTrans, 1); 279 | MTrans = RotateY(MTrans, 3); 280 | MTrans = RotateZ(MTrans, 5); 281 | MTrans = Translate(MTrans, Q[8].V[0], Q[8].V[1], Q[8].V[2]); 282 | MQube = MMulti(MTrans, MQube); 283 | var i = 8; 284 | for (; i > -1; i--) { 285 | Q[i].V = VMulti(MTrans, Q[i].V); 286 | } 287 | DrawQube(); 288 | Testing.LoopCount++; 289 | Loop(); 290 | } 291 | 292 | function Init(CubeSize) { 293 | // init/reset vars 294 | Origin.V = [150,150,20,1]; 295 | Testing.LoopCount = 0; 296 | Testing.LoopMax = 50; 297 | Testing.TimeMax = 0; 298 | Testing.TimeAvg = 0; 299 | Testing.TimeMin = 0; 300 | Testing.TimeTemp = 0; 301 | Testing.TimeTotal = 0; 302 | Testing.Init = false; 303 | 304 | // transformation matrix 305 | MTrans = [ 306 | [1,0,0,0], 307 | [0,1,0,0], 308 | [0,0,1,0], 309 | [0,0,0,1] 310 | ]; 311 | 312 | // position information of qube 313 | MQube = [ 314 | [1,0,0,0], 315 | [0,1,0,0], 316 | [0,0,1,0], 317 | [0,0,0,1] 318 | ]; 319 | 320 | // entity matrix 321 | I = [ 322 | [1,0,0,0], 323 | [0,1,0,0], 324 | [0,0,1,0], 325 | [0,0,0,1] 326 | ]; 327 | 328 | // create qube 329 | Q[0] = new CreateP(-CubeSize,-CubeSize, CubeSize); 330 | Q[1] = new CreateP(-CubeSize, CubeSize, CubeSize); 331 | Q[2] = new CreateP( CubeSize, CubeSize, CubeSize); 332 | Q[3] = new CreateP( CubeSize,-CubeSize, CubeSize); 333 | Q[4] = new CreateP(-CubeSize,-CubeSize,-CubeSize); 334 | Q[5] = new CreateP(-CubeSize, CubeSize,-CubeSize); 335 | Q[6] = new CreateP( CubeSize, CubeSize,-CubeSize); 336 | Q[7] = new CreateP( CubeSize,-CubeSize,-CubeSize); 337 | 338 | // center of gravity 339 | Q[8] = new CreateP(0, 0, 0); 340 | 341 | // anti-clockwise edge check 342 | Q.Edge = [[0,1,2],[3,2,6],[7,6,5],[4,5,1],[4,0,3],[1,5,6]]; 343 | 344 | // calculate squad normals 345 | Q.Normal = new Array(); 346 | for (var i = 0; i < Q.Edge.length; i++) Q.Normal[i] = CalcNormal(Q[Q.Edge[i][0]].V, Q[Q.Edge[i][1]].V, Q[Q.Edge[i][2]].V); 347 | 348 | // line drawn ? 349 | Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false]; 350 | 351 | // create line pixels 352 | Q.NumPx = 9 * 2 * CubeSize; 353 | for (var i = 0; i < Q.NumPx; i++) CreateP(0,0,0); 354 | 355 | MTrans = Translate(MTrans, Origin.V[0], Origin.V[1], Origin.V[2]); 356 | MQube = MMulti(MTrans, MQube); 357 | 358 | var i = 0; 359 | for (; i < 9; i++) { 360 | Q[i].V = VMulti(MTrans, Q[i].V); 361 | } 362 | DrawQube(); 363 | Testing.Init = true; 364 | Loop(); 365 | 366 | // Perform a simple sum-based verification. 367 | var sum = 0; 368 | for (var i = 0; i < Q.length; ++i) { 369 | var vector = Q[i].V; 370 | for (var j = 0; j < vector.length; ++j) 371 | sum += vector[j]; 372 | } 373 | if (sum != validation[CubeSize]) 374 | throw "Error: bad vector sum for CubeSize = " + CubeSize + "; expected " + validation[CubeSize] + " but got " + sum; 375 | } 376 | 377 | for ( var i = 20; i <= 160; i *= 2 ) { 378 | Init(i); 379 | } 380 | 381 | Q = null; 382 | MTrans = null; 383 | MQube = null; 384 | I = null; 385 | Origin = null; 386 | Testing = null; 387 | LoopTime = null; 388 | DisplArea = null; 389 | 390 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 391 | 392 | console.log("### TIME:", _sunSpiderInterval, "ms"); 393 | -------------------------------------------------------------------------------- /SunSpider/3d-morph.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* 36 | * Copyright (C) 2007 Apple Inc. All rights reserved. 37 | * 38 | * Redistribution and use in source and binary forms, with or without 39 | * modification, are permitted provided that the following conditions 40 | * are met: 41 | * 1. Redistributions of source code must retain the above copyright 42 | * notice, this list of conditions and the following disclaimer. 43 | * 2. Redistributions in binary form must reproduce the above copyright 44 | * notice, this list of conditions and the following disclaimer in the 45 | * documentation and/or other materials provided with the distribution. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 48 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 50 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 51 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 52 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 53 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 54 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 55 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 56 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | */ 59 | 60 | var loops = 15 61 | var nx = 120 62 | var nz = 120 63 | 64 | function morph(a, f) { 65 | var PI2nx = Math.PI * 8/nx 66 | var sin = Math.sin 67 | var f30 = -(50 * sin(f*Math.PI*2)) 68 | 69 | for (var i = 0; i < nz; ++i) { 70 | for (var j = 0; j < nx; ++j) { 71 | a[3*(i*nx+j)+1] = sin((j-1) * PI2nx ) * -f30 72 | } 73 | } 74 | } 75 | 76 | 77 | var a = Array() 78 | for (var i=0; i < nx*nz*3; ++i) 79 | a[i] = 0 80 | 81 | for (var i = 0; i < loops; ++i) { 82 | morph(a, i/loops) 83 | } 84 | 85 | testOutput = 0; 86 | for (var i = 0; i < nx; i++) 87 | testOutput += a[3*(i*nx+i)+1]; 88 | a = null; 89 | 90 | // This has to be an approximate test since ECMAscript doesn't formally specify 91 | // what sin() returns. Even if it did specify something like for example what Java 7 92 | // says - that sin() has to return a value within 1 ulp of exact - then we still 93 | // would not be able to do an exact test here since that would allow for just enough 94 | // low-bit slop to create possibly big errors due to testOutput being a sum. 95 | var epsilon = 1e-13; 96 | if (Math.abs(testOutput) >= epsilon) 97 | throw "Error: bad test output: expected magnitude below " + epsilon + " but got " + testOutput; 98 | 99 | 100 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 101 | 102 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/access-binary-trees.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* The Great Computer Language Shootout 36 | http://shootout.alioth.debian.org/ 37 | contributed by Isaac Gouy */ 38 | 39 | function TreeNode(left,right,item){ 40 | this.left = left; 41 | this.right = right; 42 | this.item = item; 43 | } 44 | 45 | TreeNode.prototype.itemCheck = function(){ 46 | if (this.left==null) return this.item; 47 | else return this.item + this.left.itemCheck() - this.right.itemCheck(); 48 | } 49 | 50 | function bottomUpTree(item,depth){ 51 | if (depth>0){ 52 | return new TreeNode( 53 | bottomUpTree(2*item-1, depth-1) 54 | ,bottomUpTree(2*item, depth-1) 55 | ,item 56 | ); 57 | } 58 | else { 59 | return new TreeNode(null,null,item); 60 | } 61 | } 62 | 63 | var ret = 0; 64 | 65 | for ( var n = 4; n <= 7; n += 1 ) { 66 | var minDepth = 4; 67 | var maxDepth = Math.max(minDepth + 2, n); 68 | var stretchDepth = maxDepth + 1; 69 | 70 | var check = bottomUpTree(0,stretchDepth).itemCheck(); 71 | 72 | var longLivedTree = bottomUpTree(0,maxDepth); 73 | for (var depth=minDepth; depth<=maxDepth; depth+=2){ 74 | var iterations = 1 << (maxDepth - depth + minDepth); 75 | 76 | check = 0; 77 | for (var i=1; i<=iterations; i++){ 78 | check += bottomUpTree(i,depth).itemCheck(); 79 | check += bottomUpTree(-i,depth).itemCheck(); 80 | } 81 | } 82 | 83 | ret += longLivedTree.itemCheck(); 84 | } 85 | 86 | var expected = -4; 87 | if (ret != expected) 88 | throw "ERROR: bad result: expected " + expected + " but got " + ret; 89 | 90 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 91 | 92 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/access-fannkuch.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* The Great Computer Language Shootout 36 | http://shootout.alioth.debian.org/ 37 | contributed by Isaac Gouy */ 38 | 39 | function fannkuch(n) { 40 | var check = 0; 41 | var perm = Array(n); 42 | var perm1 = Array(n); 43 | var count = Array(n); 44 | var maxPerm = Array(n); 45 | var maxFlipsCount = 0; 46 | var m = n - 1; 47 | 48 | for (var i = 0; i < n; i++) perm1[i] = i; 49 | var r = n; 50 | 51 | while (true) { 52 | // write-out the first 30 permutations 53 | if (check < 30){ 54 | var s = ""; 55 | for(var i=0; i> 1; 68 | for (var i = 0; i < k2; i++) { 69 | var temp = perm[i]; perm[i] = perm[k - i]; perm[k - i] = temp; 70 | } 71 | flipsCount++; 72 | } 73 | 74 | if (flipsCount > maxFlipsCount) { 75 | maxFlipsCount = flipsCount; 76 | for (var i = 0; i < n; i++) maxPerm[i] = perm1[i]; 77 | } 78 | } 79 | 80 | while (true) { 81 | if (r == n) return maxFlipsCount; 82 | var perm0 = perm1[0]; 83 | var i = 0; 84 | while (i < r) { 85 | var j = i + 1; 86 | perm1[i] = perm1[j]; 87 | i = j; 88 | } 89 | perm1[r] = perm0; 90 | 91 | count[r] = count[r] - 1; 92 | if (count[r] > 0) break; 93 | r++; 94 | } 95 | } 96 | } 97 | 98 | var n = 8; 99 | var ret = fannkuch(n); 100 | 101 | var expected = 22; 102 | if (ret != expected) 103 | throw "ERROR: bad result: expected " + expected + " but got " + ret; 104 | 105 | 106 | 107 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 108 | 109 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/access-nbody.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* The Great Computer Language Shootout 36 | http://shootout.alioth.debian.org/ 37 | contributed by Isaac Gouy */ 38 | 39 | var PI = 3.141592653589793; 40 | var SOLAR_MASS = 4 * PI * PI; 41 | var DAYS_PER_YEAR = 365.24; 42 | 43 | function Body(x,y,z,vx,vy,vz,mass){ 44 | this.x = x; 45 | this.y = y; 46 | this.z = z; 47 | this.vx = vx; 48 | this.vy = vy; 49 | this.vz = vz; 50 | this.mass = mass; 51 | } 52 | 53 | Body.prototype.offsetMomentum = function(px,py,pz) { 54 | this.vx = -px / SOLAR_MASS; 55 | this.vy = -py / SOLAR_MASS; 56 | this.vz = -pz / SOLAR_MASS; 57 | return this; 58 | } 59 | 60 | function Jupiter(){ 61 | return new Body( 62 | 4.84143144246472090e+00, 63 | -1.16032004402742839e+00, 64 | -1.03622044471123109e-01, 65 | 1.66007664274403694e-03 * DAYS_PER_YEAR, 66 | 7.69901118419740425e-03 * DAYS_PER_YEAR, 67 | -6.90460016972063023e-05 * DAYS_PER_YEAR, 68 | 9.54791938424326609e-04 * SOLAR_MASS 69 | ); 70 | } 71 | 72 | function Saturn(){ 73 | return new Body( 74 | 8.34336671824457987e+00, 75 | 4.12479856412430479e+00, 76 | -4.03523417114321381e-01, 77 | -2.76742510726862411e-03 * DAYS_PER_YEAR, 78 | 4.99852801234917238e-03 * DAYS_PER_YEAR, 79 | 2.30417297573763929e-05 * DAYS_PER_YEAR, 80 | 2.85885980666130812e-04 * SOLAR_MASS 81 | ); 82 | } 83 | 84 | function Uranus(){ 85 | return new Body( 86 | 1.28943695621391310e+01, 87 | -1.51111514016986312e+01, 88 | -2.23307578892655734e-01, 89 | 2.96460137564761618e-03 * DAYS_PER_YEAR, 90 | 2.37847173959480950e-03 * DAYS_PER_YEAR, 91 | -2.96589568540237556e-05 * DAYS_PER_YEAR, 92 | 4.36624404335156298e-05 * SOLAR_MASS 93 | ); 94 | } 95 | 96 | function Neptune(){ 97 | return new Body( 98 | 1.53796971148509165e+01, 99 | -2.59193146099879641e+01, 100 | 1.79258772950371181e-01, 101 | 2.68067772490389322e-03 * DAYS_PER_YEAR, 102 | 1.62824170038242295e-03 * DAYS_PER_YEAR, 103 | -9.51592254519715870e-05 * DAYS_PER_YEAR, 104 | 5.15138902046611451e-05 * SOLAR_MASS 105 | ); 106 | } 107 | 108 | function Sun(){ 109 | return new Body(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS); 110 | } 111 | 112 | 113 | function NBodySystem(bodies){ 114 | this.bodies = bodies; 115 | var px = 0.0; 116 | var py = 0.0; 117 | var pz = 0.0; 118 | var size = this.bodies.length; 119 | for (var i=0; i0){ 44 | for (var i=1; i<=prefixWidth; i++) s = " " + s; 45 | } 46 | return s; 47 | } 48 | 49 | function nsieve(m, isPrime){ 50 | var i, k, count; 51 | 52 | for (i=2; i<=m; i++) { isPrime[i] = true; } 53 | count = 0; 54 | 55 | for (i=2; i<=m; i++){ 56 | if (isPrime[i]) { 57 | for (k=i+i; k<=m; k+=i) isPrime[k] = false; 58 | count++; 59 | } 60 | } 61 | return count; 62 | } 63 | 64 | function sieve() { 65 | var sum = 0; 66 | for (var i = 1; i <= 3; i++ ) { 67 | var m = (1<> ((b << 1) & 14)); 44 | c += 3 & (bi3b >> ((b >> 2) & 14)); 45 | c += 3 & (bi3b >> ((b >> 5) & 6)); 46 | return c; 47 | 48 | /* 49 | lir4,0xE994; 9 instructions, no memory access, minimal register dependence, 6 shifts, 2 adds, 1 inline assign 50 | rlwinmr5,r3,1,28,30 51 | rlwinmr6,r3,30,28,30 52 | rlwinmr7,r3,27,29,30 53 | rlwnmr8,r4,r5,30,31 54 | rlwnmr9,r4,r6,30,31 55 | rlwnmr10,r4,r7,30,31 56 | addr3,r8,r9 57 | addr3,r3,r10 58 | */ 59 | } 60 | 61 | 62 | function TimeFunc(func) { 63 | var x, y, t; 64 | var sum = 0; 65 | for(var x=0; x<500; x++) 66 | for(var y=0; y<256; y++) sum += func(y); 67 | return sum; 68 | } 69 | 70 | sum = TimeFunc(fast3bitlookup); 71 | 72 | var expected = 512000; 73 | if (sum != expected) 74 | throw "ERROR: bad result: expected " + expected + " but got " + sum; 75 | 76 | 77 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 78 | 79 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/bitops-bits-in-byte.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | // Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com) 36 | 37 | 38 | var result = 0; 39 | 40 | // 1 op = 2 assigns, 16 compare/branches, 8 ANDs, (0-8) ADDs, 8 SHLs 41 | // O(n) 42 | function bitsinbyte(b) { 43 | var m = 1, c = 0; 44 | while(m<0x100) { 45 | if(b & m) c++; 46 | m <<= 1; 47 | } 48 | return c; 49 | } 50 | 51 | function TimeFunc(func) { 52 | var x, y, t; 53 | var sum = 0; 54 | for(var x=0; x<350; x++) 55 | for(var y=0; y<256; y++) sum += func(y); 56 | return sum; 57 | } 58 | 59 | result = TimeFunc(bitsinbyte); 60 | 61 | var expected = 358400; 62 | if (result != expected) 63 | throw "ERROR: bad result: expected " + expected + " but got " + result; 64 | 65 | 66 | 67 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 68 | 69 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/bitops-bitwise-and.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* 36 | * Copyright (C) 2007 Apple Inc. All rights reserved. 37 | * 38 | * Redistribution and use in source and binary forms, with or without 39 | * modification, are permitted provided that the following conditions 40 | * are met: 41 | * 1. Redistributions of source code must retain the above copyright 42 | * notice, this list of conditions and the following disclaimer. 43 | * 2. Redistributions in binary form must reproduce the above copyright 44 | * notice, this list of conditions and the following disclaimer in the 45 | * documentation and/or other materials provided with the distribution. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 48 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 50 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 51 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 52 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 53 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 54 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 55 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 56 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | */ 59 | 60 | bitwiseAndValue = 4294967296; 61 | for (var i = 0; i < 600000; i++) 62 | bitwiseAndValue = bitwiseAndValue & i; 63 | 64 | var result = bitwiseAndValue; 65 | 66 | var expected = 0; 67 | if (result != expected) 68 | throw "ERROR: bad result: expected " + expected + " but got " + result; 69 | 70 | 71 | 72 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 73 | 74 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/bitops-nsieve-bits.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | // The Great Computer Language Shootout 36 | // http://shootout.alioth.debian.org 37 | // 38 | // Contributed by Ian Osgood 39 | 40 | function pad(n,width) { 41 | var s = n.toString(); 42 | while (s.length < width) s = ' ' + s; 43 | return s; 44 | } 45 | 46 | function primes(isPrime, n) { 47 | var i, count = 0, m = 10000<>5; 48 | 49 | for (i=0; i>5] & 1<<(i&31)) { 53 | for (var j=i+i; j>5] &= ~(1<<(j&31)); 55 | count++; 56 | } 57 | } 58 | 59 | function sieve() { 60 | for (var i = 4; i <= 4; i++) { 61 | var isPrime = new Array((10000<>5); 62 | primes(isPrime, i); 63 | } 64 | return isPrime; 65 | } 66 | 67 | var result = sieve(); 68 | 69 | var sum = 0; 70 | for (var i = 0; i < result.length; ++i) 71 | sum += result[i]; 72 | 73 | var expected = -1286749544853; 74 | if (sum != expected) 75 | throw "ERROR: bad result: expected " + expected + " but got " + sum; 76 | 77 | 78 | 79 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 80 | 81 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/controlflow-recursive.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | // The Computer Language Shootout 36 | // http://shootout.alioth.debian.org/ 37 | // contributed by Isaac Gouy 38 | 39 | function ack(m,n){ 40 | if (m==0) { return n+1; } 41 | if (n==0) { return ack(m-1,1); } 42 | return ack(m-1, ack(m,n-1) ); 43 | } 44 | 45 | function fib(n) { 46 | if (n < 2){ return 1; } 47 | return fib(n-2) + fib(n-1); 48 | } 49 | 50 | function tak(x,y,z) { 51 | if (y >= x) return z; 52 | return tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y)); 53 | } 54 | 55 | var result = 0; 56 | 57 | for ( var i = 3; i <= 5; i++ ) { 58 | result += ack(3,i); 59 | result += fib(17.0+i); 60 | result += tak(3*i+3,2*i+2,i+1); 61 | } 62 | 63 | var expected = 57775; 64 | if (result != expected) 65 | throw "ERROR: bad result: expected " + expected + " but got " + result; 66 | 67 | 68 | 69 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 70 | 71 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/crypto-md5.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* 36 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message 37 | * Digest Algorithm, as defined in RFC 1321. 38 | * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. 39 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 40 | * Distributed under the BSD License 41 | * See http://pajhome.org.uk/crypt/md5 for more info. 42 | */ 43 | 44 | /* 45 | * Configurable variables. You may need to tweak these to be compatible with 46 | * the server-side, but the defaults work in most cases. 47 | */ 48 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 49 | var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 50 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 51 | 52 | /* 53 | * These are the functions you'll usually want to call 54 | * They take string arguments and return either hex or base-64 encoded strings 55 | */ 56 | function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));} 57 | function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));} 58 | function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));} 59 | function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); } 60 | function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); } 61 | function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); } 62 | 63 | /* 64 | * Perform a simple self-test to see if the VM is working 65 | */ 66 | function md5_vm_test() 67 | { 68 | return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; 69 | } 70 | 71 | /* 72 | * Calculate the MD5 of an array of little-endian words, and a bit length 73 | */ 74 | function core_md5(x, len) 75 | { 76 | /* append padding */ 77 | x[len >> 5] |= 0x80 << ((len) % 32); 78 | x[(((len + 64) >>> 9) << 4) + 14] = len; 79 | 80 | var a = 1732584193; 81 | var b = -271733879; 82 | var c = -1732584194; 83 | var d = 271733878; 84 | 85 | for(var i = 0; i < x.length; i += 16) 86 | { 87 | var olda = a; 88 | var oldb = b; 89 | var oldc = c; 90 | var oldd = d; 91 | 92 | a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); 93 | d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); 94 | c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); 95 | b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); 96 | a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); 97 | d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); 98 | c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); 99 | b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); 100 | a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); 101 | d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); 102 | c = md5_ff(c, d, a, b, x[i+10], 17, -42063); 103 | b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); 104 | a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); 105 | d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); 106 | c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); 107 | b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); 108 | 109 | a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); 110 | d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); 111 | c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); 112 | b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); 113 | a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); 114 | d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); 115 | c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); 116 | b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); 117 | a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); 118 | d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); 119 | c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); 120 | b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); 121 | a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); 122 | d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); 123 | c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); 124 | b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); 125 | 126 | a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); 127 | d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); 128 | c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); 129 | b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); 130 | a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); 131 | d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); 132 | c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); 133 | b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); 134 | a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); 135 | d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); 136 | c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); 137 | b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); 138 | a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); 139 | d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); 140 | c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); 141 | b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); 142 | 143 | a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); 144 | d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); 145 | c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); 146 | b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); 147 | a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); 148 | d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); 149 | c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); 150 | b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); 151 | a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); 152 | d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); 153 | c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); 154 | b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); 155 | a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); 156 | d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); 157 | c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); 158 | b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); 159 | 160 | a = safe_add(a, olda); 161 | b = safe_add(b, oldb); 162 | c = safe_add(c, oldc); 163 | d = safe_add(d, oldd); 164 | } 165 | return Array(a, b, c, d); 166 | 167 | } 168 | 169 | /* 170 | * These functions implement the four basic operations the algorithm uses. 171 | */ 172 | function md5_cmn(q, a, b, x, s, t) 173 | { 174 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); 175 | } 176 | function md5_ff(a, b, c, d, x, s, t) 177 | { 178 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); 179 | } 180 | function md5_gg(a, b, c, d, x, s, t) 181 | { 182 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); 183 | } 184 | function md5_hh(a, b, c, d, x, s, t) 185 | { 186 | return md5_cmn(b ^ c ^ d, a, b, x, s, t); 187 | } 188 | function md5_ii(a, b, c, d, x, s, t) 189 | { 190 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 191 | } 192 | 193 | /* 194 | * Calculate the HMAC-MD5, of a key and some data 195 | */ 196 | function core_hmac_md5(key, data) 197 | { 198 | var bkey = str2binl(key); 199 | if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz); 200 | 201 | var ipad = Array(16), opad = Array(16); 202 | for(var i = 0; i < 16; i++) 203 | { 204 | ipad[i] = bkey[i] ^ 0x36363636; 205 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 206 | } 207 | 208 | var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); 209 | return core_md5(opad.concat(hash), 512 + 128); 210 | } 211 | 212 | /* 213 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 214 | * to work around bugs in some JS interpreters. 215 | */ 216 | function safe_add(x, y) 217 | { 218 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 219 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 220 | return (msw << 16) | (lsw & 0xFFFF); 221 | } 222 | 223 | /* 224 | * Bitwise rotate a 32-bit number to the left. 225 | */ 226 | function bit_rol(num, cnt) 227 | { 228 | return (num << cnt) | (num >>> (32 - cnt)); 229 | } 230 | 231 | /* 232 | * Convert a string to an array of little-endian words 233 | * If chrsz is ASCII, characters >255 have their hi-byte silently ignored. 234 | */ 235 | function str2binl(str) 236 | { 237 | var bin = Array(); 238 | var mask = (1 << chrsz) - 1; 239 | for(var i = 0; i < str.length * chrsz; i += chrsz) 240 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32); 241 | return bin; 242 | } 243 | 244 | /* 245 | * Convert an array of little-endian words to a string 246 | */ 247 | function binl2str(bin) 248 | { 249 | var str = ""; 250 | var mask = (1 << chrsz) - 1; 251 | for(var i = 0; i < bin.length * 32; i += chrsz) 252 | str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask); 253 | return str; 254 | } 255 | 256 | /* 257 | * Convert an array of little-endian words to a hex string. 258 | */ 259 | function binl2hex(binarray) 260 | { 261 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 262 | var str = ""; 263 | for(var i = 0; i < binarray.length * 4; i++) 264 | { 265 | str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) + 266 | hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF); 267 | } 268 | return str; 269 | } 270 | 271 | /* 272 | * Convert an array of little-endian words to a base-64 string 273 | */ 274 | function binl2b64(binarray) 275 | { 276 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 277 | var str = ""; 278 | for(var i = 0; i < binarray.length * 4; i += 3) 279 | { 280 | var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) 281 | | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) 282 | | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF); 283 | for(var j = 0; j < 4; j++) 284 | { 285 | if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; 286 | else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); 287 | } 288 | } 289 | return str; 290 | } 291 | 292 | var plainText = "Rebellious subjects, enemies to peace,\n\ 293 | Profaners of this neighbour-stained steel,--\n\ 294 | Will they not hear? What, ho! you men, you beasts,\n\ 295 | That quench the fire of your pernicious rage\n\ 296 | With purple fountains issuing from your veins,\n\ 297 | On pain of torture, from those bloody hands\n\ 298 | Throw your mistemper'd weapons to the ground,\n\ 299 | And hear the sentence of your moved prince.\n\ 300 | Three civil brawls, bred of an airy word,\n\ 301 | By thee, old Capulet, and Montague,\n\ 302 | Have thrice disturb'd the quiet of our streets,\n\ 303 | And made Verona's ancient citizens\n\ 304 | Cast by their grave beseeming ornaments,\n\ 305 | To wield old partisans, in hands as old,\n\ 306 | Canker'd with peace, to part your canker'd hate:\n\ 307 | If ever you disturb our streets again,\n\ 308 | Your lives shall pay the forfeit of the peace.\n\ 309 | For this time, all the rest depart away:\n\ 310 | You Capulet; shall go along with me:\n\ 311 | And, Montague, come you this afternoon,\n\ 312 | To know our further pleasure in this case,\n\ 313 | To old Free-town, our common judgment-place.\n\ 314 | Once more, on pain of death, all men depart." 315 | 316 | for (var i = 0; i <4; i++) { 317 | plainText += plainText; 318 | } 319 | 320 | var md5Output = hex_md5(plainText); 321 | 322 | var expected = "a831e91e0f70eddcb70dc61c6f82f6cd"; 323 | 324 | if (md5Output != expected) 325 | throw "ERROR: bad result: expected " + expected + " but got " + md5Output; 326 | 327 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 328 | 329 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/crypto-sha1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* 36 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined 37 | * in FIPS PUB 180-1 38 | * Version 2.1a Copyright Paul Johnston 2000 - 2002. 39 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 40 | * Distributed under the BSD License 41 | * See http://pajhome.org.uk/crypt/md5 for details. 42 | */ 43 | 44 | /* 45 | * Configurable variables. You may need to tweak these to be compatible with 46 | * the server-side, but the defaults work in most cases. 47 | */ 48 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 49 | var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 50 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 51 | 52 | /* 53 | * These are the functions you'll usually want to call 54 | * They take string arguments and return either hex or base-64 encoded strings 55 | */ 56 | function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));} 57 | function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));} 58 | function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));} 59 | function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));} 60 | function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));} 61 | function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));} 62 | 63 | /* 64 | * Perform a simple self-test to see if the VM is working 65 | */ 66 | function sha1_vm_test() 67 | { 68 | return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d"; 69 | } 70 | 71 | /* 72 | * Calculate the SHA-1 of an array of big-endian words, and a bit length 73 | */ 74 | function core_sha1(x, len) 75 | { 76 | /* append padding */ 77 | x[len >> 5] |= 0x80 << (24 - len % 32); 78 | x[((len + 64 >> 9) << 4) + 15] = len; 79 | 80 | var w = Array(80); 81 | var a = 1732584193; 82 | var b = -271733879; 83 | var c = -1732584194; 84 | var d = 271733878; 85 | var e = -1009589776; 86 | 87 | for(var i = 0; i < x.length; i += 16) 88 | { 89 | var olda = a; 90 | var oldb = b; 91 | var oldc = c; 92 | var oldd = d; 93 | var olde = e; 94 | 95 | for(var j = 0; j < 80; j++) 96 | { 97 | if(j < 16) w[j] = x[i + j]; 98 | else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); 99 | var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), 100 | safe_add(safe_add(e, w[j]), sha1_kt(j))); 101 | e = d; 102 | d = c; 103 | c = rol(b, 30); 104 | b = a; 105 | a = t; 106 | } 107 | 108 | a = safe_add(a, olda); 109 | b = safe_add(b, oldb); 110 | c = safe_add(c, oldc); 111 | d = safe_add(d, oldd); 112 | e = safe_add(e, olde); 113 | } 114 | return Array(a, b, c, d, e); 115 | 116 | } 117 | 118 | /* 119 | * Perform the appropriate triplet combination function for the current 120 | * iteration 121 | */ 122 | function sha1_ft(t, b, c, d) 123 | { 124 | if(t < 20) return (b & c) | ((~b) & d); 125 | if(t < 40) return b ^ c ^ d; 126 | if(t < 60) return (b & c) | (b & d) | (c & d); 127 | return b ^ c ^ d; 128 | } 129 | 130 | /* 131 | * Determine the appropriate additive constant for the current iteration 132 | */ 133 | function sha1_kt(t) 134 | { 135 | return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : 136 | (t < 60) ? -1894007588 : -899497514; 137 | } 138 | 139 | /* 140 | * Calculate the HMAC-SHA1 of a key and some data 141 | */ 142 | function core_hmac_sha1(key, data) 143 | { 144 | var bkey = str2binb(key); 145 | if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz); 146 | 147 | var ipad = Array(16), opad = Array(16); 148 | for(var i = 0; i < 16; i++) 149 | { 150 | ipad[i] = bkey[i] ^ 0x36363636; 151 | opad[i] = bkey[i] ^ 0x5C5C5C5C; 152 | } 153 | 154 | var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); 155 | return core_sha1(opad.concat(hash), 512 + 160); 156 | } 157 | 158 | /* 159 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally 160 | * to work around bugs in some JS interpreters. 161 | */ 162 | function safe_add(x, y) 163 | { 164 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 165 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 166 | return (msw << 16) | (lsw & 0xFFFF); 167 | } 168 | 169 | /* 170 | * Bitwise rotate a 32-bit number to the left. 171 | */ 172 | function rol(num, cnt) 173 | { 174 | return (num << cnt) | (num >>> (32 - cnt)); 175 | } 176 | 177 | /* 178 | * Convert an 8-bit or 16-bit string to an array of big-endian words 179 | * In 8-bit function, characters >255 have their hi-byte silently ignored. 180 | */ 181 | function str2binb(str) 182 | { 183 | var bin = Array(); 184 | var mask = (1 << chrsz) - 1; 185 | for(var i = 0; i < str.length * chrsz; i += chrsz) 186 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32); 187 | return bin; 188 | } 189 | 190 | /* 191 | * Convert an array of big-endian words to a string 192 | */ 193 | function binb2str(bin) 194 | { 195 | var str = ""; 196 | var mask = (1 << chrsz) - 1; 197 | for(var i = 0; i < bin.length * 32; i += chrsz) 198 | str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask); 199 | return str; 200 | } 201 | 202 | /* 203 | * Convert an array of big-endian words to a hex string. 204 | */ 205 | function binb2hex(binarray) 206 | { 207 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 208 | var str = ""; 209 | for(var i = 0; i < binarray.length * 4; i++) 210 | { 211 | str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + 212 | hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF); 213 | } 214 | return str; 215 | } 216 | 217 | /* 218 | * Convert an array of big-endian words to a base-64 string 219 | */ 220 | function binb2b64(binarray) 221 | { 222 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 223 | var str = ""; 224 | for(var i = 0; i < binarray.length * 4; i += 3) 225 | { 226 | var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16) 227 | | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 ) 228 | | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF); 229 | for(var j = 0; j < 4; j++) 230 | { 231 | if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; 232 | else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); 233 | } 234 | } 235 | return str; 236 | } 237 | 238 | 239 | var plainText = "Two households, both alike in dignity,\n\ 240 | In fair Verona, where we lay our scene,\n\ 241 | From ancient grudge break to new mutiny,\n\ 242 | Where civil blood makes civil hands unclean.\n\ 243 | From forth the fatal loins of these two foes\n\ 244 | A pair of star-cross'd lovers take their life;\n\ 245 | Whole misadventured piteous overthrows\n\ 246 | Do with their death bury their parents' strife.\n\ 247 | The fearful passage of their death-mark'd love,\n\ 248 | And the continuance of their parents' rage,\n\ 249 | Which, but their children's end, nought could remove,\n\ 250 | Is now the two hours' traffic of our stage;\n\ 251 | The which if you with patient ears attend,\n\ 252 | What here shall miss, our toil shall strive to mend."; 253 | 254 | for (var i = 0; i <4; i++) { 255 | plainText += plainText; 256 | } 257 | 258 | var sha1Output = hex_sha1(plainText); 259 | 260 | var expected = "2524d264def74cce2498bf112bedf00e6c0b796d"; 261 | if (sha1Output != expected) 262 | throw "ERROR: bad result: expected " + expected + " but got " + sha1Output; 263 | 264 | 265 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 266 | 267 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/date-format-tofte.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | function arrayExists(array, x) { 36 | for (var i = 0; i < array.length; i++) { 37 | if (array[i] == x) return true; 38 | } 39 | return false; 40 | } 41 | 42 | Date.prototype.formatDate = function (input,time) { 43 | // formatDate : 44 | // a PHP date like function, for formatting date strings 45 | // See: http://www.php.net/date 46 | // 47 | // input : format string 48 | // time : epoch time (seconds, and optional) 49 | // 50 | // if time is not passed, formatting is based on 51 | // the current "this" date object's set time. 52 | // 53 | // supported: 54 | // a, A, B, d, D, F, g, G, h, H, i, j, l (lowercase L), L, 55 | // m, M, n, O, r, s, S, t, U, w, W, y, Y, z 56 | // 57 | // unsupported: 58 | // I (capital i), T, Z 59 | 60 | var switches = ["a", "A", "B", "d", "D", "F", "g", "G", "h", "H", 61 | "i", "j", "l", "L", "m", "M", "n", "O", "r", "s", 62 | "S", "t", "U", "w", "W", "y", "Y", "z"]; 63 | var daysLong = ["Sunday", "Monday", "Tuesday", "Wednesday", 64 | "Thursday", "Friday", "Saturday"]; 65 | var daysShort = ["Sun", "Mon", "Tue", "Wed", 66 | "Thu", "Fri", "Sat"]; 67 | var monthsShort = ["Jan", "Feb", "Mar", "Apr", 68 | "May", "Jun", "Jul", "Aug", "Sep", 69 | "Oct", "Nov", "Dec"]; 70 | var monthsLong = ["January", "February", "March", "April", 71 | "May", "June", "July", "August", "September", 72 | "October", "November", "December"]; 73 | var daysSuffix = ["st", "nd", "rd", "th", "th", "th", "th", // 1st - 7th 74 | "th", "th", "th", "th", "th", "th", "th", // 8th - 14th 75 | "th", "th", "th", "th", "th", "th", "st", // 15th - 21st 76 | "nd", "rd", "th", "th", "th", "th", "th", // 22nd - 28th 77 | "th", "th", "st"]; // 29th - 31st 78 | 79 | function a() { 80 | // Lowercase Ante meridiem and Post meridiem 81 | return self.getHours() > 11? "pm" : "am"; 82 | } 83 | function A() { 84 | // Uppercase Ante meridiem and Post meridiem 85 | return self.getHours() > 11? "PM" : "AM"; 86 | } 87 | 88 | function B(){ 89 | // Swatch internet time. code simply grabbed from ppk, 90 | // since I was feeling lazy: 91 | // http://www.xs4all.nl/~ppk/js/beat.html 92 | var off = (self.getTimezoneOffset() + 60)*60; 93 | var theSeconds = (self.getHours() * 3600) + 94 | (self.getMinutes() * 60) + 95 | self.getSeconds() + off; 96 | var beat = Math.floor(theSeconds/86.4); 97 | if (beat > 1000) beat -= 1000; 98 | if (beat < 0) beat += 1000; 99 | if ((""+beat).length == 1) beat = "00"+beat; 100 | if ((""+beat).length == 2) beat = "0"+beat; 101 | return beat; 102 | } 103 | 104 | function d() { 105 | // Day of the month, 2 digits with leading zeros 106 | return new String(self.getDate()).length == 1? 107 | "0"+self.getDate() : self.getDate(); 108 | } 109 | function D() { 110 | // A textual representation of a day, three letters 111 | return daysShort[self.getDay()]; 112 | } 113 | function F() { 114 | // A full textual representation of a month 115 | return monthsLong[self.getMonth()]; 116 | } 117 | function g() { 118 | // 12-hour format of an hour without leading zeros 119 | return self.getHours() > 12? self.getHours()-12 : self.getHours(); 120 | } 121 | function G() { 122 | // 24-hour format of an hour without leading zeros 123 | return self.getHours(); 124 | } 125 | function h() { 126 | // 12-hour format of an hour with leading zeros 127 | if (self.getHours() > 12) { 128 | var s = new String(self.getHours()-12); 129 | return s.length == 1? 130 | "0"+ (self.getHours()-12) : self.getHours()-12; 131 | } else { 132 | var s = new String(self.getHours()); 133 | return s.length == 1? 134 | "0"+self.getHours() : self.getHours(); 135 | } 136 | } 137 | function H() { 138 | // 24-hour format of an hour with leading zeros 139 | return new String(self.getHours()).length == 1? 140 | "0"+self.getHours() : self.getHours(); 141 | } 142 | function i() { 143 | // Minutes with leading zeros 144 | return new String(self.getMinutes()).length == 1? 145 | "0"+self.getMinutes() : self.getMinutes(); 146 | } 147 | function j() { 148 | // Day of the month without leading zeros 149 | return self.getDate(); 150 | } 151 | function l() { 152 | // A full textual representation of the day of the week 153 | return daysLong[self.getDay()]; 154 | } 155 | function L() { 156 | // leap year or not. 1 if leap year, 0 if not. 157 | // the logic should match iso's 8601 standard. 158 | var y_ = Y(); 159 | if ( 160 | (y_ % 4 == 0 && y_ % 100 != 0) || 161 | (y_ % 4 == 0 && y_ % 100 == 0 && y_ % 400 == 0) 162 | ) { 163 | return 1; 164 | } else { 165 | return 0; 166 | } 167 | } 168 | function m() { 169 | // Numeric representation of a month, with leading zeros 170 | return self.getMonth() < 9? 171 | "0"+(self.getMonth()+1) : 172 | self.getMonth()+1; 173 | } 174 | function M() { 175 | // A short textual representation of a month, three letters 176 | return monthsShort[self.getMonth()]; 177 | } 178 | function n() { 179 | // Numeric representation of a month, without leading zeros 180 | return self.getMonth()+1; 181 | } 182 | function O() { 183 | // Difference to Greenwich time (GMT) in hours 184 | var os = Math.abs(self.getTimezoneOffset()); 185 | var h = ""+Math.floor(os/60); 186 | var m = ""+(os%60); 187 | h.length == 1? h = "0"+h:1; 188 | m.length == 1? m = "0"+m:1; 189 | return self.getTimezoneOffset() < 0 ? "+"+h+m : "-"+h+m; 190 | } 191 | function r() { 192 | // RFC 822 formatted date 193 | var r; // result 194 | // Thu , 21 Dec 2000 195 | r = D() + ", " + j() + " " + M() + " " + Y() + 196 | // 16 : 01 : 07 +0200 197 | " " + H() + ":" + i() + ":" + s() + " " + O(); 198 | return r; 199 | } 200 | function S() { 201 | // English ordinal suffix for the day of the month, 2 characters 202 | return daysSuffix[self.getDate()-1]; 203 | } 204 | function s() { 205 | // Seconds, with leading zeros 206 | return new String(self.getSeconds()).length == 1? 207 | "0"+self.getSeconds() : self.getSeconds(); 208 | } 209 | function t() { 210 | 211 | // thanks to Matt Bannon for some much needed code-fixes here! 212 | var daysinmonths = [null,31,28,31,30,31,30,31,31,30,31,30,31]; 213 | if (L()==1 && n()==2) return 29; // leap day 214 | return daysinmonths[n()]; 215 | } 216 | function U() { 217 | // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 218 | return Math.round(self.getTime()/1000); 219 | } 220 | function W() { 221 | // Weeknumber, as per ISO specification: 222 | // http://www.cl.cam.ac.uk/~mgk25/iso-time.html 223 | 224 | // if the day is three days before newyears eve, 225 | // there's a chance it's "week 1" of next year. 226 | // here we check for that. 227 | var beforeNY = 364+L() - z(); 228 | var afterNY = z(); 229 | var weekday = w()!=0?w()-1:6; // makes sunday (0), into 6. 230 | if (beforeNY <= 2 && weekday <= 2-beforeNY) { 231 | return 1; 232 | } 233 | // similarly, if the day is within threedays of newyears 234 | // there's a chance it belongs in the old year. 235 | var ny = new Date("January 1 " + Y() + " 00:00:00"); 236 | var nyDay = ny.getDay()!=0?ny.getDay()-1:6; 237 | if ( 238 | (afterNY <= 2) && 239 | (nyDay >=4) && 240 | (afterNY >= (6-nyDay)) 241 | ) { 242 | // Since I'm not sure we can just always return 53, 243 | // i call the function here again, using the last day 244 | // of the previous year, as the date, and then just 245 | // return that week. 246 | var prevNY = new Date("December 31 " + (Y()-1) + " 00:00:00"); 247 | return prevNY.formatDate("W"); 248 | } 249 | 250 | // week 1, is the week that has the first thursday in it. 251 | // note that this value is not zero index. 252 | if (nyDay <= 3) { 253 | // first day of the year fell on a thursday, or earlier. 254 | return 1 + Math.floor( ( z() + nyDay ) / 7 ); 255 | } else { 256 | // first day of the year fell on a friday, or later. 257 | return 1 + Math.floor( ( z() - ( 7 - nyDay ) ) / 7 ); 258 | } 259 | } 260 | function w() { 261 | // Numeric representation of the day of the week 262 | return self.getDay(); 263 | } 264 | 265 | function Y() { 266 | // A full numeric representation of a year, 4 digits 267 | 268 | // we first check, if getFullYear is supported. if it 269 | // is, we just use that. ppks code is nice, but wont 270 | // work with dates outside 1900-2038, or something like that 271 | if (self.getFullYear) { 272 | var newDate = new Date("January 1 2001 00:00:00 +0000"); 273 | var x = newDate .getFullYear(); 274 | if (x == 2001) { 275 | // i trust the method now 276 | return self.getFullYear(); 277 | } 278 | } 279 | // else, do this: 280 | // codes thanks to ppk: 281 | // http://www.xs4all.nl/~ppk/js/introdate.html 282 | var x = self.getYear(); 283 | var y = x % 100; 284 | y += (y < 38) ? 2000 : 1900; 285 | return y; 286 | } 287 | function y() { 288 | // A two-digit representation of a year 289 | var y = Y()+""; 290 | return y.substring(y.length-2,y.length); 291 | } 292 | function z() { 293 | // The day of the year, zero indexed! 0 through 366 294 | var t = new Date("January 1 " + Y() + " 00:00:00"); 295 | var diff = self.getTime() - t.getTime(); 296 | return Math.floor(diff/1000/60/60/24); 297 | } 298 | 299 | var self = this; 300 | if (time) { 301 | // save time 302 | var prevTime = self.getTime(); 303 | self.setTime(time); 304 | } 305 | 306 | var ia = input.split(""); 307 | var ij = 0; 308 | while (ia[ij]) { 309 | if (ia[ij] == "\\\\") { 310 | // this is our way of allowing users to escape stuff 311 | ia.splice(ij,1); 312 | } else { 313 | if (arrayExists(switches,ia[ij])) { 314 | ia[ij] = eval(ia[ij] + "()"); 315 | } 316 | } 317 | ij++; 318 | } 319 | // reset time, back to what it was 320 | if (prevTime) { 321 | self.setTime(prevTime); 322 | } 323 | return ia.join(""); 324 | } 325 | 326 | var date = new Date("1/1/2007 1:11:11"); 327 | 328 | for (i = 0; i < 500; ++i) { 329 | var shortFormat = date.formatDate("Y-m-d"); 330 | var longFormat = date.formatDate("l, F d, Y g:i:s A"); 331 | date.setTime(date.getTime() + 84266956); 332 | } 333 | 334 | // FIXME: Find a way to validate this test. 335 | // https://bugs.webkit.org/show_bug.cgi?id=114849 336 | 337 | 338 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 339 | 340 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/math-cordic.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | /* 36 | * Copyright (C) Rich Moore. All rights reserved. 37 | * 38 | * Redistribution and use in source and binary forms, with or without 39 | * modification, are permitted provided that the following conditions 40 | * are met: 41 | * 1. Redistributions of source code must retain the above copyright 42 | * notice, this list of conditions and the following disclaimer. 43 | * 2. Redistributions in binary form must reproduce the above copyright 44 | * notice, this list of conditions and the following disclaimer in the 45 | * documentation and/or other materials provided with the distribution. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY 48 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 50 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 51 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 52 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 53 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 54 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 55 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 56 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | */ 59 | 60 | /////. Start CORDIC 61 | 62 | var AG_CONST = 0.6072529350; 63 | 64 | function FIXED(X) 65 | { 66 | return X * 65536.0; 67 | } 68 | 69 | function FLOAT(X) 70 | { 71 | return X / 65536.0; 72 | } 73 | 74 | function DEG2RAD(X) 75 | { 76 | return 0.017453 * (X); 77 | } 78 | 79 | var Angles = [ 80 | FIXED(45.0), FIXED(26.565), FIXED(14.0362), FIXED(7.12502), 81 | FIXED(3.57633), FIXED(1.78991), FIXED(0.895174), FIXED(0.447614), 82 | FIXED(0.223811), FIXED(0.111906), FIXED(0.055953), 83 | FIXED(0.027977) 84 | ]; 85 | 86 | var Target = 28.027; 87 | 88 | function cordicsincos(Target) { 89 | var X; 90 | var Y; 91 | var TargetAngle; 92 | var CurrAngle; 93 | var Step; 94 | 95 | X = FIXED(AG_CONST); /* AG_CONST * cos(0) */ 96 | Y = 0; /* AG_CONST * sin(0) */ 97 | 98 | TargetAngle = FIXED(Target); 99 | CurrAngle = 0; 100 | for (Step = 0; Step < 12; Step++) { 101 | var NewX; 102 | if (TargetAngle > CurrAngle) { 103 | NewX = X - (Y >> Step); 104 | Y = (X >> Step) + Y; 105 | X = NewX; 106 | CurrAngle += Angles[Step]; 107 | } else { 108 | NewX = X + (Y >> Step); 109 | Y = -(X >> Step) + Y; 110 | X = NewX; 111 | CurrAngle -= Angles[Step]; 112 | } 113 | } 114 | 115 | return FLOAT(X) * FLOAT(Y); 116 | } 117 | 118 | ///// End CORDIC 119 | 120 | var total = 0; 121 | 122 | function cordic( runs ) { 123 | var start = new Date(); 124 | 125 | for ( var i = 0 ; i < runs ; i++ ) { 126 | total += cordicsincos(Target); 127 | } 128 | 129 | var end = new Date(); 130 | 131 | return end.getTime() - start.getTime(); 132 | } 133 | 134 | cordic(25000); 135 | 136 | var expected = 10362.570468755888; 137 | 138 | if (total != expected) 139 | throw "ERROR: bad result: expected " + expected + " but got " + total; 140 | 141 | 142 | 143 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 144 | 145 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/math-partial-sums.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | // The Computer Language Shootout 36 | // http://shootout.alioth.debian.org/ 37 | // contributed by Isaac Gouy 38 | 39 | function partial(n){ 40 | var a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 0.0; 41 | var twothirds = 2.0/3.0; 42 | var alt = -1.0; 43 | var k2 = k3 = sk = ck = 0.0; 44 | 45 | for (var k = 1; k <= n; k++){ 46 | k2 = k*k; 47 | k3 = k2*k; 48 | sk = Math.sin(k); 49 | ck = Math.cos(k); 50 | alt = -alt; 51 | 52 | a1 += Math.pow(twothirds,k-1); 53 | a2 += Math.pow(k,-0.5); 54 | a3 += 1.0/(k*(k+1.0)); 55 | a4 += 1.0/(k3 * sk*sk); 56 | a5 += 1.0/(k3 * ck*ck); 57 | a6 += 1.0/k; 58 | a7 += 1.0/k2; 59 | a8 += alt/k; 60 | a9 += alt/(2*k -1); 61 | } 62 | 63 | // NOTE: We don't try to validate anything from pow(), sin() or cos() because those aren't 64 | // well-specified in ECMAScript. 65 | return a6 + a7 + a8 + a9; 66 | } 67 | 68 | var total = 0; 69 | 70 | for (var i = 1024; i <= 16384; i *= 2) { 71 | total += partial(i); 72 | } 73 | 74 | var expected = 60.08994194659945; 75 | 76 | if (total != expected) { 77 | throw "ERROR: bad result: expected " + expected + " but got " + total; 78 | } 79 | 80 | 81 | 82 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 83 | 84 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/math-spectral-norm.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORhS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | // The Great Computer Language Shootout 36 | // http://shootout.alioth.debian.org/ 37 | // 38 | // contributed by Ian Osgood 39 | 40 | function A(i,j) { 41 | return 1/((i+j)*(i+j+1)/2+i+1); 42 | } 43 | 44 | function Au(u,v) { 45 | for (var i=0; i (original author) 57 | * Samuel Sieb 58 | * 59 | * Alternatively, the contents of this file may be used under the terms of 60 | * either the GNU General Public License Version 2 or later (the "GPL"), or 61 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 62 | * in which case the provisions of the GPL or the LGPL are applicable instead 63 | * of those above. If you wish to allow use of your version of this file only 64 | * under the terms of either the GPL or the LGPL, and not to allow others to 65 | * use your version of this file under the terms of the MPL, indicate your 66 | * decision by deleting the provisions above and replace them with the notice 67 | * and other provisions required by the GPL or the LGPL. If you do not delete 68 | * the provisions above, a recipient may use your version of this file under 69 | * the terms of any one of the MPL, the GPL or the LGPL. 70 | * 71 | * ***** END LICENSE BLOCK ***** */ 72 | 73 | // From: http://lxr.mozilla.org/mozilla/source/extensions/xml-rpc/src/nsXmlRpcClient.js#956 74 | 75 | /* Convert data (an array of integers) to a Base64 string. */ 76 | var toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; 77 | var base64Pad = '='; 78 | 79 | function toBase64(data) { 80 | var result = ''; 81 | var length = data.length; 82 | var i; 83 | // Convert every three bytes to 4 ascii characters. 84 | for (i = 0; i < (length - 2); i += 3) { 85 | result += toBase64Table[data.charCodeAt(i) >> 2]; 86 | result += toBase64Table[((data.charCodeAt(i) & 0x03) << 4) + (data.charCodeAt(i+1) >> 4)]; 87 | result += toBase64Table[((data.charCodeAt(i+1) & 0x0f) << 2) + (data.charCodeAt(i+2) >> 6)]; 88 | result += toBase64Table[data.charCodeAt(i+2) & 0x3f]; 89 | } 90 | 91 | // Convert the remaining 1 or 2 bytes, pad out to 4 characters. 92 | if (length%3) { 93 | i = length - (length%3); 94 | result += toBase64Table[data.charCodeAt(i) >> 2]; 95 | if ((length%3) == 2) { 96 | result += toBase64Table[((data.charCodeAt(i) & 0x03) << 4) + (data.charCodeAt(i+1) >> 4)]; 97 | result += toBase64Table[(data.charCodeAt(i+1) & 0x0f) << 2]; 98 | result += base64Pad; 99 | } else { 100 | result += toBase64Table[(data.charCodeAt(i) & 0x03) << 4]; 101 | result += base64Pad + base64Pad; 102 | } 103 | } 104 | 105 | return result; 106 | } 107 | 108 | /* Convert Base64 data to a string */ 109 | var toBinaryTable = [ 110 | -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, 111 | -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, 112 | -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63, 113 | 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1, 114 | -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14, 115 | 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1, 116 | -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40, 117 | 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1 118 | ]; 119 | 120 | function base64ToString(data) { 121 | var result = ''; 122 | var leftbits = 0; // number of bits decoded, but yet to be appended 123 | var leftdata = 0; // bits decoded, but yet to be appended 124 | 125 | // Convert one by one. 126 | for (var i = 0; i < data.length; i++) { 127 | var c = toBinaryTable[data.charCodeAt(i) & 0x7f]; 128 | var padding = (data.charCodeAt(i) == base64Pad.charCodeAt(0)); 129 | // Skip illegal characters and whitespace 130 | if (c == -1) continue; 131 | 132 | // Collect data into leftdata, update bitcount 133 | leftdata = (leftdata << 6) | c; 134 | leftbits += 6; 135 | 136 | // If we have 8 or more bits, append 8 bits to the result 137 | if (leftbits >= 8) { 138 | leftbits -= 8; 139 | // Append if not padding. 140 | if (!padding) 141 | result += String.fromCharCode((leftdata >> leftbits) & 0xff); 142 | leftdata &= (1 << leftbits) - 1; 143 | } 144 | } 145 | 146 | // If there are any bits left, the base64 string was corrupted 147 | if (leftbits) 148 | throw Components.Exception('Corrupted base64 string'); 149 | 150 | return result; 151 | } 152 | 153 | var str = ""; 154 | 155 | for ( var i = 0; i < 8192; i++ ) 156 | str += String.fromCharCode( (25 * Math.random()) + 97 ); 157 | 158 | for ( var i = 8192; i <= 16384; i *= 2 ) { 159 | 160 | var base64; 161 | 162 | base64 = toBase64(str); 163 | var encoded = base64ToString(base64); 164 | if (encoded != str) 165 | throw "ERROR: bad result: expected " + str + " but got " + encoded; 166 | 167 | // Double the string 168 | str += str; 169 | } 170 | 171 | toBinaryTable = null; 172 | 173 | 174 | var _sunSpiderInterval = new Date() - _sunSpiderStartDate; 175 | 176 | console.log("### TIME:", _sunSpiderInterval, "ms"); -------------------------------------------------------------------------------- /SunSpider/string-fasta.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007 Apple Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | function record(time) { 27 | document.getElementById("console").innerHTML = time + "ms"; 28 | if (window.parent) { 29 | parent.recordResult(time); 30 | } 31 | } 32 | 33 | var _sunSpiderStartDate = new Date(); 34 | 35 | // The Great Computer Language Shootout 36 | // http://shootout.alioth.debian.org 37 | // 38 | // Contributed by Ian Osgood 39 | 40 | var last = 42, A = 3877, C = 29573, M = 139968; 41 | 42 | function rand(max) { 43 | last = (last * A + C) % M; 44 | return max * last / M; 45 | } 46 | 47 | var ALU = 48 | "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + 49 | "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + 50 | "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + 51 | "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" + 52 | "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" + 53 | "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" + 54 | "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; 55 | 56 | var IUB = { 57 | a:0.27, c:0.12, g:0.12, t:0.27, 58 | B:0.02, D:0.02, H:0.02, K:0.02, 59 | M:0.02, N:0.02, R:0.02, S:0.02, 60 | V:0.02, W:0.02, Y:0.02 61 | } 62 | 63 | var HomoSap = { 64 | a: 0.3029549426680, 65 | c: 0.1979883004921, 66 | g: 0.1975473066391, 67 | t: 0.3015094502008 68 | } 69 | 70 | function makeCumulative(table) { 71 | var last = null; 72 | for (var c in table) { 73 | if (last) table[c] += table[last]; 74 | last = c; 75 | } 76 | } 77 | 78 | function fastaRepeat(n, seq) { 79 | var seqi = 0, lenOut = 60; 80 | while (n>0) { 81 | if (n0) { 98 | if (n "9") { 77 | zipGood = false; 78 | r = zip + " contains letters."; 79 | addResult(r); 80 | } 81 | } 82 | if (zipGood && zip.length>5) 83 | { 84 | zipGood = false; 85 | r = zip + " is longer than five characters."; 86 | addResult(r); 87 | } 88 | if (zipGood) 89 | { 90 | r = zip + " appears to be a valid ZIP code."; 91 | addResult(r); 92 | } 93 | } 94 | } 95 | 96 | function makeName(n) 97 | { 98 | var tmp = ""; 99 | for (var i=0;i 1 else 0 14 | interval = stderr * stats.t.ppf((1 + confidence) / 2., n-1) if n > 1 else 0 15 | return mean - interval, mean + interval 16 | 17 | def calculate_totals(data): 18 | totals = {} 19 | for suite, tests in data.items(): 20 | suite_total = sum(test["mean"] for test in tests.values()) 21 | totals[suite] = suite_total 22 | all_suites_total = sum(totals.values()) 23 | return totals, all_suites_total 24 | 25 | def main(): 26 | parser = argparse.ArgumentParser(description="Compare JavaScript benchmark results.") 27 | parser.add_argument("-o", "--old", required=True, help="Old JSON results file.") 28 | parser.add_argument("-n", "--new", required=True, help="New JSON results file.") 29 | args = parser.parse_args() 30 | 31 | with open(args.old, "r") as f: 32 | old_data = json.load(f) 33 | with open(args.new, "r") as f: 34 | new_data = json.load(f) 35 | 36 | old_totals, old_all_suites_total = calculate_totals(old_data) 37 | new_totals, new_all_suites_total = calculate_totals(new_data) 38 | 39 | table_data = [] 40 | for suite in old_data.keys(): 41 | if suite not in new_data: 42 | continue 43 | for test in old_data[suite].keys(): 44 | if test not in new_data[suite]: 45 | continue 46 | old_mean = old_data[suite][test]["mean"] 47 | new_mean = new_data[suite][test]["mean"] 48 | old_min = min(old_data[suite][test]["runs"]) 49 | new_min = min(new_data[suite][test]["runs"]) 50 | old_max = max(old_data[suite][test]["runs"]) 51 | new_max = max(new_data[suite][test]["runs"]) 52 | speedup = old_mean / new_mean 53 | formatted_speedup = f"{speedup:.3f}" 54 | table_data.append([suite, test, formatted_speedup, f"{old_mean:.3f} ± {old_min:.3f} … {old_max:.3f}", f"{new_mean:.3f} ± {new_min:.3f} … {new_max:.3f}"]) 55 | 56 | # Add total times comparison to the table data 57 | for suite in old_totals.keys(): 58 | if suite in new_totals: 59 | speedup = old_totals[suite] / new_totals[suite] 60 | table_data.append([suite, "Total", f"{speedup:.3f}", f"{old_totals[suite]:.3f}", f"{new_totals[suite]:.3f}"]) 61 | 62 | # Compare all suites total 63 | all_suites_speedup = old_all_suites_total / new_all_suites_total 64 | table_data.append(["All Suites", "Total", f"{all_suites_speedup:.3f}", f"{old_all_suites_total:.3f}", f"{new_all_suites_total:.3f}"]) 65 | 66 | print(tabulate(table_data, headers=["Suite", "Test", "Speedup", "Old (Mean ± Range)", "New (Mean ± Range)"])) 67 | 68 | if __name__ == "__main__": 69 | main() 70 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.26.2 2 | scipy==1.15.2 3 | tabulate==0.9.0 4 | -------------------------------------------------------------------------------- /run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import json 5 | import os 6 | import subprocess 7 | import statistics 8 | import sys 9 | from tabulate import tabulate 10 | 11 | def run_benchmark(executable, suite, test_file, iterations, index, total, suppress_output=False): 12 | times = [] 13 | for i in range(iterations): 14 | if not suppress_output: 15 | print(f"[{index}/{total}] {suite}/{test_file} (Iteration {i+1}/{iterations}, Avg: {statistics.mean(times):.3f}s)" if times else f"[{index}/{total}] {suite}/{test_file} (Iteration {i+1}/{iterations})", end="\r") 16 | sys.stdout.flush() 17 | 18 | result = subprocess.run([f"time -p {executable} {suite}/{test_file}"], shell=True, stderr=subprocess.PIPE, stdout=subprocess.DEVNULL, text=True, executable="/bin/bash") 19 | result.check_returncode() 20 | 21 | time_output = result.stderr.split("\n") 22 | real_time_line = [line for line in time_output if "real" in line][0] 23 | time_taken = float(real_time_line.split(" ")[-1]) 24 | times.append(time_taken) 25 | 26 | mean = statistics.mean(times) 27 | stdev = statistics.stdev(times) if len(times) > 1 else 0 28 | min_time = min(times) 29 | max_time = max(times) 30 | if not suppress_output: 31 | print(f"[{index}/{total}] {suite}/{test_file} completed. Mean: {mean:.3f}s ± {stdev:.3f}s, Range: {min_time:.3f}s … {max_time:.3f}s\033[K") 32 | sys.stdout.flush() 33 | 34 | return mean, stdev, min_time, max_time, times 35 | 36 | def main(): 37 | parser = argparse.ArgumentParser(description="Run JavaScript benchmarks.") 38 | parser.add_argument("--executable", "-e", default="js", help="Path to the JavaScript executable.") 39 | parser.add_argument("--iterations", "-i", type=int, default=3, help="Number of iterations for each test.") 40 | parser.add_argument("--suites", "-s", default="all", help="Comma-separated list of suites to run.") 41 | parser.add_argument("--warmups", "-w", type=int, default=0, help="Number of warm-up runs of SunSpider.") 42 | parser.add_argument("--output", "-o", default="results.json", help="JSON output file name.") 43 | args = parser.parse_args() 44 | 45 | if args.suites == "all": 46 | suites = ["SunSpider", "Kraken", "Octane", "JetStream", "JetStream3", "RegExp", "MicroBench"] 47 | else: 48 | suites = args.suites.split(",") 49 | 50 | if args.warmups > 0: 51 | print("Performing warm-up runs of SunSpider...") 52 | for _ in range(args.warmups): 53 | for test_file in sorted(os.listdir("SunSpider")): 54 | if not test_file.endswith(".js"): 55 | continue 56 | run_benchmark(args.executable, "SunSpider", test_file, 1, 0, 0, suppress_output=True) 57 | 58 | results = {} 59 | table_data = [] 60 | total_tests = sum(len(os.listdir(suite)) for suite in suites) 61 | current_test = 1 62 | 63 | for suite in suites: 64 | results[suite] = {} 65 | for test_file in sorted(os.listdir(suite)): 66 | if not test_file.endswith(".js"): 67 | continue 68 | mean, stdev, min_time, max_time, runs = run_benchmark(args.executable, suite, test_file, args.iterations, current_test, total_tests) 69 | results[suite][test_file] = { 70 | "mean": mean, 71 | "stdev": stdev, 72 | "min": min_time, 73 | "max": max_time, 74 | "runs": runs 75 | } 76 | table_data.append([suite, test_file, f"{mean:.3f} ± {stdev:.3f}", f"{min_time:.3f} … {max_time:.3f}"]) 77 | current_test += 1 78 | 79 | print(tabulate(table_data, headers=["Suite", "Test", "Mean ± σ", "Range (min … max)"])) 80 | 81 | with open(args.output, "w") as f: 82 | json.dump(results, f, indent=4) 83 | 84 | if __name__ == "__main__": 85 | main() 86 | --------------------------------------------------------------------------------