haikuwebkit/PerformanceTests/JetStream/Octane2/splay.js

422 lines
11 KiB
JavaScript
Raw Permalink Normal View History

Add JetStream to PerformanceTests https://bugs.webkit.org/show_bug.cgi?id=144024 Rubber-stamped by Filip Pizlo. * JetStream: Added. * JetStream/JetStream-Logo.png: Added. * JetStream/JetStream-Logo@2x.png: Added. * JetStream/JetStream.css: Added. * JetStream/JetStreamDriver.js: Added. * JetStream/LICENSE.txt: Added. * JetStream/LLVM-test-suite-LICENSE.txt: Added. * JetStream/Octane: Added. * JetStream/Octane/base.js: Added. * JetStream/Octane/code-load.js: Added. * JetStream/Octane2: Added. * JetStream/Octane2/base.js: Added. * JetStream/Octane2/box2d.js: Added. * JetStream/Octane2/code-load.js: Added. * JetStream/Octane2/crypto.js: Added. * JetStream/Octane2/deltablue.js: Added. * JetStream/Octane2/earley-boyer.js: Added. * JetStream/Octane2/gbemu-part1.js: Added. * JetStream/Octane2/gbemu-part2.js: Added. * JetStream/Octane2/mandreel.js: Added. * JetStream/Octane2/navier-stokes.js: Added. * JetStream/Octane2/pdfjs.js: Added. * JetStream/Octane2/raytrace.js: Added. * JetStream/Octane2/regexp.js: Added. * JetStream/Octane2/richards.js: Added. * JetStream/Octane2/run.js: Added. * JetStream/Octane2/splay.js: Added. * JetStream/Octane2/typescript-compiler.js: Added. * JetStream/Octane2/typescript-input.js: Added. * JetStream/Octane2/typescript.js: Added. * JetStream/Octane2/zlib-data.js: Added. * JetStream/Octane2/zlib.js: Added. * JetStream/Octane2Setup.js: Added. * JetStream/OctaneSetup.js: Added. * JetStream/README: Added. * JetStream/Reference.js: Added. * JetStream/SimpleSetup.js: Added. * JetStream/SunSpiderSetup.js: Added. * JetStream/Swoosh.png: Added. * JetStream/Swoosh@2x.png: Added. * JetStream/TestingSetup.js: Added. * JetStream/create.rb: Added. * JetStream/docs: Added. * JetStream/docs/JetStreamBlogPost.html: Added. * JetStream/in-depth-TEMPLATE.html: Added. * JetStream/index-TEMPLATE.html: Added. * JetStream/simple: Added. * JetStream/simple/bigfib.cpp: Added. * JetStream/simple/bigfib.cpp.js: Added. * JetStream/simple/container.cpp: Added. * JetStream/simple/container.cpp.js: Added. * JetStream/simple/dry.c: Added. * JetStream/simple/dry.c.js: Added. * JetStream/simple/float-mm.c: Added. * JetStream/simple/float-mm.c.js: Added. * JetStream/simple/gcc-loops.cpp: Added. * JetStream/simple/gcc-loops.cpp.js: Added. * JetStream/simple/hash-map.js: Added. * JetStream/simple/n-body.c: Added. * JetStream/simple/n-body.c.js: Added. * JetStream/simple/quicksort.c: Added. * JetStream/simple/quicksort.c.js: Added. * JetStream/simple/towers.c: Added. * JetStream/simple/towers.c.js: Added. * JetStream/sunspider: Added. * JetStream/sunspider/3d-cube.js: Added. * JetStream/sunspider/3d-raytrace.js: Added. * JetStream/sunspider/base64.js: Added. * JetStream/sunspider/cordic.js: Added. * JetStream/sunspider/crypto-aes.js: Added. * JetStream/sunspider/crypto-md5.js: Added. * JetStream/sunspider/crypto-sha1.js: Added. * JetStream/sunspider/date-format-tofte.js: Added. * JetStream/sunspider/date-format-xparb.js: Added. * JetStream/sunspider/n-body.js: Added. * JetStream/sunspider/regex-dna.js: Added. * JetStream/sunspider/tagcloud.js: Added. Canonical link: https://commits.webkit.org/161992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-22 02:30:22 +00:00
// Copyright 2009 the V8 project authors. All rights reserved.
JetStream should have a more rational story for jitter-oriented latency tests https://bugs.webkit.org/show_bug.cgi?id=145762 Reviewed by Geoffrey Garen. JetStream has some latency tests that are meant to measure jitter. Prior to this change, they did this by computing the RMS. But the RMS is a pretty bad metric. The thing that it rewards isn't really the thing that you'd want your browser to do. These RMS-based tests involve taking the geomean of the RMS of some samples and the sample average. The lower the geomean, the better (in the JetStream harness we then invert the scores so that higher is better, but let's ignore that for this discussion and assume that lower is better). Here's an example of how this can go bad. A browser that always computes a task in some horribly long time (say, 1000ms) but never varies that time will perform better than a browser that usually computes the task super quickly (say, 10ms) and sometimes just a little bit less quickly (say, 15ms). The former browser will have an RMS of 0 and an average of 1000. The latter will have a RMS somewhere around 3.5 and an average of 12.5 (assuming equal probability of 10ms and 15ms). The geomean of (0, 1000) is 0. The geomean of (3.5, 12.5) is 6.6. Lower is better, so the former browser scores higher - even though it's obviously never better to have a browser always complete a task in 1000ms when a different browser can do it in 15ms in the worst case. JetStream should not have this pathology. The right way of avoiding it is to replace RMS with some other metric of how bad things get. A good metric is the average of the worst percentile. The worst 1% or the worst 5% would be good things to average. This will catch cases where the VM jittered due to JIT or GC, but it never have the pathology that we end up giving the better score to a VM whose best case is worst than another VM's worst case. For now, this change uses the highest samples above the 95% percentile. I'm not yet sure if that is the best thing - it might include too many scores that are around the best-case performance - but it's certainly better than RMS and it might be good enough to keep. But because of that uncertainty, I'm setting the version to be "1.1-alpha1" to indicate that we aren't ready to release this yet. * JetStream/Octane2/base.js: (.this.Setup.setup.setup): (.this.TearDown.tearDown.tearDown): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.RunSingleBenchmark): * JetStream/Octane2/mandreel.js: (setupMandreel): (updateMandreelStats): (startMandreelTimer): (latencyMandreel): (tearDownMandreel): (RMSMandreel): Deleted. * JetStream/Octane2/splay.js: (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplayTearDown): (SplayRMS): Deleted. * JetStream/create.rb: Canonical link: https://commits.webkit.org/163895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185425 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-10 18:44:50 +00:00
// Copyright (C) 2015 Apple Inc. All rights reserved.
Add JetStream to PerformanceTests https://bugs.webkit.org/show_bug.cgi?id=144024 Rubber-stamped by Filip Pizlo. * JetStream: Added. * JetStream/JetStream-Logo.png: Added. * JetStream/JetStream-Logo@2x.png: Added. * JetStream/JetStream.css: Added. * JetStream/JetStreamDriver.js: Added. * JetStream/LICENSE.txt: Added. * JetStream/LLVM-test-suite-LICENSE.txt: Added. * JetStream/Octane: Added. * JetStream/Octane/base.js: Added. * JetStream/Octane/code-load.js: Added. * JetStream/Octane2: Added. * JetStream/Octane2/base.js: Added. * JetStream/Octane2/box2d.js: Added. * JetStream/Octane2/code-load.js: Added. * JetStream/Octane2/crypto.js: Added. * JetStream/Octane2/deltablue.js: Added. * JetStream/Octane2/earley-boyer.js: Added. * JetStream/Octane2/gbemu-part1.js: Added. * JetStream/Octane2/gbemu-part2.js: Added. * JetStream/Octane2/mandreel.js: Added. * JetStream/Octane2/navier-stokes.js: Added. * JetStream/Octane2/pdfjs.js: Added. * JetStream/Octane2/raytrace.js: Added. * JetStream/Octane2/regexp.js: Added. * JetStream/Octane2/richards.js: Added. * JetStream/Octane2/run.js: Added. * JetStream/Octane2/splay.js: Added. * JetStream/Octane2/typescript-compiler.js: Added. * JetStream/Octane2/typescript-input.js: Added. * JetStream/Octane2/typescript.js: Added. * JetStream/Octane2/zlib-data.js: Added. * JetStream/Octane2/zlib.js: Added. * JetStream/Octane2Setup.js: Added. * JetStream/OctaneSetup.js: Added. * JetStream/README: Added. * JetStream/Reference.js: Added. * JetStream/SimpleSetup.js: Added. * JetStream/SunSpiderSetup.js: Added. * JetStream/Swoosh.png: Added. * JetStream/Swoosh@2x.png: Added. * JetStream/TestingSetup.js: Added. * JetStream/create.rb: Added. * JetStream/docs: Added. * JetStream/docs/JetStreamBlogPost.html: Added. * JetStream/in-depth-TEMPLATE.html: Added. * JetStream/index-TEMPLATE.html: Added. * JetStream/simple: Added. * JetStream/simple/bigfib.cpp: Added. * JetStream/simple/bigfib.cpp.js: Added. * JetStream/simple/container.cpp: Added. * JetStream/simple/container.cpp.js: Added. * JetStream/simple/dry.c: Added. * JetStream/simple/dry.c.js: Added. * JetStream/simple/float-mm.c: Added. * JetStream/simple/float-mm.c.js: Added. * JetStream/simple/gcc-loops.cpp: Added. * JetStream/simple/gcc-loops.cpp.js: Added. * JetStream/simple/hash-map.js: Added. * JetStream/simple/n-body.c: Added. * JetStream/simple/n-body.c.js: Added. * JetStream/simple/quicksort.c: Added. * JetStream/simple/quicksort.c.js: Added. * JetStream/simple/towers.c: Added. * JetStream/simple/towers.c.js: Added. * JetStream/sunspider: Added. * JetStream/sunspider/3d-cube.js: Added. * JetStream/sunspider/3d-raytrace.js: Added. * JetStream/sunspider/base64.js: Added. * JetStream/sunspider/cordic.js: Added. * JetStream/sunspider/crypto-aes.js: Added. * JetStream/sunspider/crypto-md5.js: Added. * JetStream/sunspider/crypto-sha1.js: Added. * JetStream/sunspider/date-format-tofte.js: Added. * JetStream/sunspider/date-format-xparb.js: Added. * JetStream/sunspider/n-body.js: Added. * JetStream/sunspider/regex-dna.js: Added. * JetStream/sunspider/tagcloud.js: Added. Canonical link: https://commits.webkit.org/161992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-22 02:30:22 +00:00
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This benchmark is based on a JavaScript log processing module used
// by the V8 profiler to generate execution time profiles for runs of
// JavaScript applications, and it effectively measures how fast the
// JavaScript engine is at allocating nodes and reclaiming the memory
// used for old nodes. Because of the way splay trees work, the engine
// also has to deal with a lot of changes to the large tree object
// graph.
var Splay = new BenchmarkSuite('Splay', [81491, 2739514], [
new Benchmark("Splay", true, false,
JetStream should have a more rational story for jitter-oriented latency tests https://bugs.webkit.org/show_bug.cgi?id=145762 Reviewed by Geoffrey Garen. JetStream has some latency tests that are meant to measure jitter. Prior to this change, they did this by computing the RMS. But the RMS is a pretty bad metric. The thing that it rewards isn't really the thing that you'd want your browser to do. These RMS-based tests involve taking the geomean of the RMS of some samples and the sample average. The lower the geomean, the better (in the JetStream harness we then invert the scores so that higher is better, but let's ignore that for this discussion and assume that lower is better). Here's an example of how this can go bad. A browser that always computes a task in some horribly long time (say, 1000ms) but never varies that time will perform better than a browser that usually computes the task super quickly (say, 10ms) and sometimes just a little bit less quickly (say, 15ms). The former browser will have an RMS of 0 and an average of 1000. The latter will have a RMS somewhere around 3.5 and an average of 12.5 (assuming equal probability of 10ms and 15ms). The geomean of (0, 1000) is 0. The geomean of (3.5, 12.5) is 6.6. Lower is better, so the former browser scores higher - even though it's obviously never better to have a browser always complete a task in 1000ms when a different browser can do it in 15ms in the worst case. JetStream should not have this pathology. The right way of avoiding it is to replace RMS with some other metric of how bad things get. A good metric is the average of the worst percentile. The worst 1% or the worst 5% would be good things to average. This will catch cases where the VM jittered due to JIT or GC, but it never have the pathology that we end up giving the better score to a VM whose best case is worst than another VM's worst case. For now, this change uses the highest samples above the 95% percentile. I'm not yet sure if that is the best thing - it might include too many scores that are around the best-case performance - but it's certainly better than RMS and it might be good enough to keep. But because of that uncertainty, I'm setting the version to be "1.1-alpha1" to indicate that we aren't ready to release this yet. * JetStream/Octane2/base.js: (.this.Setup.setup.setup): (.this.TearDown.tearDown.tearDown): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.RunSingleBenchmark): * JetStream/Octane2/mandreel.js: (setupMandreel): (updateMandreelStats): (startMandreelTimer): (latencyMandreel): (tearDownMandreel): (RMSMandreel): Deleted. * JetStream/Octane2/splay.js: (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplayTearDown): (SplayRMS): Deleted. * JetStream/create.rb: Canonical link: https://commits.webkit.org/163895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185425 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-10 18:44:50 +00:00
SplayRun, SplaySetup, SplayTearDown, SplayLatency)
Add JetStream to PerformanceTests https://bugs.webkit.org/show_bug.cgi?id=144024 Rubber-stamped by Filip Pizlo. * JetStream: Added. * JetStream/JetStream-Logo.png: Added. * JetStream/JetStream-Logo@2x.png: Added. * JetStream/JetStream.css: Added. * JetStream/JetStreamDriver.js: Added. * JetStream/LICENSE.txt: Added. * JetStream/LLVM-test-suite-LICENSE.txt: Added. * JetStream/Octane: Added. * JetStream/Octane/base.js: Added. * JetStream/Octane/code-load.js: Added. * JetStream/Octane2: Added. * JetStream/Octane2/base.js: Added. * JetStream/Octane2/box2d.js: Added. * JetStream/Octane2/code-load.js: Added. * JetStream/Octane2/crypto.js: Added. * JetStream/Octane2/deltablue.js: Added. * JetStream/Octane2/earley-boyer.js: Added. * JetStream/Octane2/gbemu-part1.js: Added. * JetStream/Octane2/gbemu-part2.js: Added. * JetStream/Octane2/mandreel.js: Added. * JetStream/Octane2/navier-stokes.js: Added. * JetStream/Octane2/pdfjs.js: Added. * JetStream/Octane2/raytrace.js: Added. * JetStream/Octane2/regexp.js: Added. * JetStream/Octane2/richards.js: Added. * JetStream/Octane2/run.js: Added. * JetStream/Octane2/splay.js: Added. * JetStream/Octane2/typescript-compiler.js: Added. * JetStream/Octane2/typescript-input.js: Added. * JetStream/Octane2/typescript.js: Added. * JetStream/Octane2/zlib-data.js: Added. * JetStream/Octane2/zlib.js: Added. * JetStream/Octane2Setup.js: Added. * JetStream/OctaneSetup.js: Added. * JetStream/README: Added. * JetStream/Reference.js: Added. * JetStream/SimpleSetup.js: Added. * JetStream/SunSpiderSetup.js: Added. * JetStream/Swoosh.png: Added. * JetStream/Swoosh@2x.png: Added. * JetStream/TestingSetup.js: Added. * JetStream/create.rb: Added. * JetStream/docs: Added. * JetStream/docs/JetStreamBlogPost.html: Added. * JetStream/in-depth-TEMPLATE.html: Added. * JetStream/index-TEMPLATE.html: Added. * JetStream/simple: Added. * JetStream/simple/bigfib.cpp: Added. * JetStream/simple/bigfib.cpp.js: Added. * JetStream/simple/container.cpp: Added. * JetStream/simple/container.cpp.js: Added. * JetStream/simple/dry.c: Added. * JetStream/simple/dry.c.js: Added. * JetStream/simple/float-mm.c: Added. * JetStream/simple/float-mm.c.js: Added. * JetStream/simple/gcc-loops.cpp: Added. * JetStream/simple/gcc-loops.cpp.js: Added. * JetStream/simple/hash-map.js: Added. * JetStream/simple/n-body.c: Added. * JetStream/simple/n-body.c.js: Added. * JetStream/simple/quicksort.c: Added. * JetStream/simple/quicksort.c.js: Added. * JetStream/simple/towers.c: Added. * JetStream/simple/towers.c.js: Added. * JetStream/sunspider: Added. * JetStream/sunspider/3d-cube.js: Added. * JetStream/sunspider/3d-raytrace.js: Added. * JetStream/sunspider/base64.js: Added. * JetStream/sunspider/cordic.js: Added. * JetStream/sunspider/crypto-aes.js: Added. * JetStream/sunspider/crypto-md5.js: Added. * JetStream/sunspider/crypto-sha1.js: Added. * JetStream/sunspider/date-format-tofte.js: Added. * JetStream/sunspider/date-format-xparb.js: Added. * JetStream/sunspider/n-body.js: Added. * JetStream/sunspider/regex-dna.js: Added. * JetStream/sunspider/tagcloud.js: Added. Canonical link: https://commits.webkit.org/161992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-22 02:30:22 +00:00
]);
// Configuration.
var kSplayTreeSize = 8000;
var kSplayTreeModifications = 80;
var kSplayTreePayloadDepth = 5;
var splayTree = null;
var splaySampleTimeStart = 0.0;
function GeneratePayloadTree(depth, tag) {
if (depth == 0) {
return {
array : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
string : 'String for key ' + tag + ' in leaf node'
};
} else {
return {
left: GeneratePayloadTree(depth - 1, tag),
right: GeneratePayloadTree(depth - 1, tag)
};
}
}
function GenerateKey() {
// The benchmark framework guarantees that Math.random is
// deterministic; see base.js.
return Math.random();
}
JetStream should have a more rational story for jitter-oriented latency tests https://bugs.webkit.org/show_bug.cgi?id=145762 Reviewed by Geoffrey Garen. JetStream has some latency tests that are meant to measure jitter. Prior to this change, they did this by computing the RMS. But the RMS is a pretty bad metric. The thing that it rewards isn't really the thing that you'd want your browser to do. These RMS-based tests involve taking the geomean of the RMS of some samples and the sample average. The lower the geomean, the better (in the JetStream harness we then invert the scores so that higher is better, but let's ignore that for this discussion and assume that lower is better). Here's an example of how this can go bad. A browser that always computes a task in some horribly long time (say, 1000ms) but never varies that time will perform better than a browser that usually computes the task super quickly (say, 10ms) and sometimes just a little bit less quickly (say, 15ms). The former browser will have an RMS of 0 and an average of 1000. The latter will have a RMS somewhere around 3.5 and an average of 12.5 (assuming equal probability of 10ms and 15ms). The geomean of (0, 1000) is 0. The geomean of (3.5, 12.5) is 6.6. Lower is better, so the former browser scores higher - even though it's obviously never better to have a browser always complete a task in 1000ms when a different browser can do it in 15ms in the worst case. JetStream should not have this pathology. The right way of avoiding it is to replace RMS with some other metric of how bad things get. A good metric is the average of the worst percentile. The worst 1% or the worst 5% would be good things to average. This will catch cases where the VM jittered due to JIT or GC, but it never have the pathology that we end up giving the better score to a VM whose best case is worst than another VM's worst case. For now, this change uses the highest samples above the 95% percentile. I'm not yet sure if that is the best thing - it might include too many scores that are around the best-case performance - but it's certainly better than RMS and it might be good enough to keep. But because of that uncertainty, I'm setting the version to be "1.1-alpha1" to indicate that we aren't ready to release this yet. * JetStream/Octane2/base.js: (.this.Setup.setup.setup): (.this.TearDown.tearDown.tearDown): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.RunSingleBenchmark): * JetStream/Octane2/mandreel.js: (setupMandreel): (updateMandreelStats): (startMandreelTimer): (latencyMandreel): (tearDownMandreel): (RMSMandreel): Deleted. * JetStream/Octane2/splay.js: (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplayTearDown): (SplayRMS): Deleted. * JetStream/create.rb: Canonical link: https://commits.webkit.org/163895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185425 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-10 18:44:50 +00:00
var splaySamples = [];
Add JetStream to PerformanceTests https://bugs.webkit.org/show_bug.cgi?id=144024 Rubber-stamped by Filip Pizlo. * JetStream: Added. * JetStream/JetStream-Logo.png: Added. * JetStream/JetStream-Logo@2x.png: Added. * JetStream/JetStream.css: Added. * JetStream/JetStreamDriver.js: Added. * JetStream/LICENSE.txt: Added. * JetStream/LLVM-test-suite-LICENSE.txt: Added. * JetStream/Octane: Added. * JetStream/Octane/base.js: Added. * JetStream/Octane/code-load.js: Added. * JetStream/Octane2: Added. * JetStream/Octane2/base.js: Added. * JetStream/Octane2/box2d.js: Added. * JetStream/Octane2/code-load.js: Added. * JetStream/Octane2/crypto.js: Added. * JetStream/Octane2/deltablue.js: Added. * JetStream/Octane2/earley-boyer.js: Added. * JetStream/Octane2/gbemu-part1.js: Added. * JetStream/Octane2/gbemu-part2.js: Added. * JetStream/Octane2/mandreel.js: Added. * JetStream/Octane2/navier-stokes.js: Added. * JetStream/Octane2/pdfjs.js: Added. * JetStream/Octane2/raytrace.js: Added. * JetStream/Octane2/regexp.js: Added. * JetStream/Octane2/richards.js: Added. * JetStream/Octane2/run.js: Added. * JetStream/Octane2/splay.js: Added. * JetStream/Octane2/typescript-compiler.js: Added. * JetStream/Octane2/typescript-input.js: Added. * JetStream/Octane2/typescript.js: Added. * JetStream/Octane2/zlib-data.js: Added. * JetStream/Octane2/zlib.js: Added. * JetStream/Octane2Setup.js: Added. * JetStream/OctaneSetup.js: Added. * JetStream/README: Added. * JetStream/Reference.js: Added. * JetStream/SimpleSetup.js: Added. * JetStream/SunSpiderSetup.js: Added. * JetStream/Swoosh.png: Added. * JetStream/Swoosh@2x.png: Added. * JetStream/TestingSetup.js: Added. * JetStream/create.rb: Added. * JetStream/docs: Added. * JetStream/docs/JetStreamBlogPost.html: Added. * JetStream/in-depth-TEMPLATE.html: Added. * JetStream/index-TEMPLATE.html: Added. * JetStream/simple: Added. * JetStream/simple/bigfib.cpp: Added. * JetStream/simple/bigfib.cpp.js: Added. * JetStream/simple/container.cpp: Added. * JetStream/simple/container.cpp.js: Added. * JetStream/simple/dry.c: Added. * JetStream/simple/dry.c.js: Added. * JetStream/simple/float-mm.c: Added. * JetStream/simple/float-mm.c.js: Added. * JetStream/simple/gcc-loops.cpp: Added. * JetStream/simple/gcc-loops.cpp.js: Added. * JetStream/simple/hash-map.js: Added. * JetStream/simple/n-body.c: Added. * JetStream/simple/n-body.c.js: Added. * JetStream/simple/quicksort.c: Added. * JetStream/simple/quicksort.c.js: Added. * JetStream/simple/towers.c: Added. * JetStream/simple/towers.c.js: Added. * JetStream/sunspider: Added. * JetStream/sunspider/3d-cube.js: Added. * JetStream/sunspider/3d-raytrace.js: Added. * JetStream/sunspider/base64.js: Added. * JetStream/sunspider/cordic.js: Added. * JetStream/sunspider/crypto-aes.js: Added. * JetStream/sunspider/crypto-md5.js: Added. * JetStream/sunspider/crypto-sha1.js: Added. * JetStream/sunspider/date-format-tofte.js: Added. * JetStream/sunspider/date-format-xparb.js: Added. * JetStream/sunspider/n-body.js: Added. * JetStream/sunspider/regex-dna.js: Added. * JetStream/sunspider/tagcloud.js: Added. Canonical link: https://commits.webkit.org/161992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-22 02:30:22 +00:00
JetStream should have a more rational story for jitter-oriented latency tests https://bugs.webkit.org/show_bug.cgi?id=145762 Reviewed by Geoffrey Garen. JetStream has some latency tests that are meant to measure jitter. Prior to this change, they did this by computing the RMS. But the RMS is a pretty bad metric. The thing that it rewards isn't really the thing that you'd want your browser to do. These RMS-based tests involve taking the geomean of the RMS of some samples and the sample average. The lower the geomean, the better (in the JetStream harness we then invert the scores so that higher is better, but let's ignore that for this discussion and assume that lower is better). Here's an example of how this can go bad. A browser that always computes a task in some horribly long time (say, 1000ms) but never varies that time will perform better than a browser that usually computes the task super quickly (say, 10ms) and sometimes just a little bit less quickly (say, 15ms). The former browser will have an RMS of 0 and an average of 1000. The latter will have a RMS somewhere around 3.5 and an average of 12.5 (assuming equal probability of 10ms and 15ms). The geomean of (0, 1000) is 0. The geomean of (3.5, 12.5) is 6.6. Lower is better, so the former browser scores higher - even though it's obviously never better to have a browser always complete a task in 1000ms when a different browser can do it in 15ms in the worst case. JetStream should not have this pathology. The right way of avoiding it is to replace RMS with some other metric of how bad things get. A good metric is the average of the worst percentile. The worst 1% or the worst 5% would be good things to average. This will catch cases where the VM jittered due to JIT or GC, but it never have the pathology that we end up giving the better score to a VM whose best case is worst than another VM's worst case. For now, this change uses the highest samples above the 95% percentile. I'm not yet sure if that is the best thing - it might include too many scores that are around the best-case performance - but it's certainly better than RMS and it might be good enough to keep. But because of that uncertainty, I'm setting the version to be "1.1-alpha1" to indicate that we aren't ready to release this yet. * JetStream/Octane2/base.js: (.this.Setup.setup.setup): (.this.TearDown.tearDown.tearDown): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.RunSingleBenchmark): * JetStream/Octane2/mandreel.js: (setupMandreel): (updateMandreelStats): (startMandreelTimer): (latencyMandreel): (tearDownMandreel): (RMSMandreel): Deleted. * JetStream/Octane2/splay.js: (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplayTearDown): (SplayRMS): Deleted. * JetStream/create.rb: Canonical link: https://commits.webkit.org/163895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185425 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-10 18:44:50 +00:00
function SplayLatency() {
return splaySamples;
Add JetStream to PerformanceTests https://bugs.webkit.org/show_bug.cgi?id=144024 Rubber-stamped by Filip Pizlo. * JetStream: Added. * JetStream/JetStream-Logo.png: Added. * JetStream/JetStream-Logo@2x.png: Added. * JetStream/JetStream.css: Added. * JetStream/JetStreamDriver.js: Added. * JetStream/LICENSE.txt: Added. * JetStream/LLVM-test-suite-LICENSE.txt: Added. * JetStream/Octane: Added. * JetStream/Octane/base.js: Added. * JetStream/Octane/code-load.js: Added. * JetStream/Octane2: Added. * JetStream/Octane2/base.js: Added. * JetStream/Octane2/box2d.js: Added. * JetStream/Octane2/code-load.js: Added. * JetStream/Octane2/crypto.js: Added. * JetStream/Octane2/deltablue.js: Added. * JetStream/Octane2/earley-boyer.js: Added. * JetStream/Octane2/gbemu-part1.js: Added. * JetStream/Octane2/gbemu-part2.js: Added. * JetStream/Octane2/mandreel.js: Added. * JetStream/Octane2/navier-stokes.js: Added. * JetStream/Octane2/pdfjs.js: Added. * JetStream/Octane2/raytrace.js: Added. * JetStream/Octane2/regexp.js: Added. * JetStream/Octane2/richards.js: Added. * JetStream/Octane2/run.js: Added. * JetStream/Octane2/splay.js: Added. * JetStream/Octane2/typescript-compiler.js: Added. * JetStream/Octane2/typescript-input.js: Added. * JetStream/Octane2/typescript.js: Added. * JetStream/Octane2/zlib-data.js: Added. * JetStream/Octane2/zlib.js: Added. * JetStream/Octane2Setup.js: Added. * JetStream/OctaneSetup.js: Added. * JetStream/README: Added. * JetStream/Reference.js: Added. * JetStream/SimpleSetup.js: Added. * JetStream/SunSpiderSetup.js: Added. * JetStream/Swoosh.png: Added. * JetStream/Swoosh@2x.png: Added. * JetStream/TestingSetup.js: Added. * JetStream/create.rb: Added. * JetStream/docs: Added. * JetStream/docs/JetStreamBlogPost.html: Added. * JetStream/in-depth-TEMPLATE.html: Added. * JetStream/index-TEMPLATE.html: Added. * JetStream/simple: Added. * JetStream/simple/bigfib.cpp: Added. * JetStream/simple/bigfib.cpp.js: Added. * JetStream/simple/container.cpp: Added. * JetStream/simple/container.cpp.js: Added. * JetStream/simple/dry.c: Added. * JetStream/simple/dry.c.js: Added. * JetStream/simple/float-mm.c: Added. * JetStream/simple/float-mm.c.js: Added. * JetStream/simple/gcc-loops.cpp: Added. * JetStream/simple/gcc-loops.cpp.js: Added. * JetStream/simple/hash-map.js: Added. * JetStream/simple/n-body.c: Added. * JetStream/simple/n-body.c.js: Added. * JetStream/simple/quicksort.c: Added. * JetStream/simple/quicksort.c.js: Added. * JetStream/simple/towers.c: Added. * JetStream/simple/towers.c.js: Added. * JetStream/sunspider: Added. * JetStream/sunspider/3d-cube.js: Added. * JetStream/sunspider/3d-raytrace.js: Added. * JetStream/sunspider/base64.js: Added. * JetStream/sunspider/cordic.js: Added. * JetStream/sunspider/crypto-aes.js: Added. * JetStream/sunspider/crypto-md5.js: Added. * JetStream/sunspider/crypto-sha1.js: Added. * JetStream/sunspider/date-format-tofte.js: Added. * JetStream/sunspider/date-format-xparb.js: Added. * JetStream/sunspider/n-body.js: Added. * JetStream/sunspider/regex-dna.js: Added. * JetStream/sunspider/tagcloud.js: Added. Canonical link: https://commits.webkit.org/161992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-22 02:30:22 +00:00
}
function SplayUpdateStats(time) {
var pause = time - splaySampleTimeStart;
splaySampleTimeStart = time;
JetStream should have a more rational story for jitter-oriented latency tests https://bugs.webkit.org/show_bug.cgi?id=145762 Reviewed by Geoffrey Garen. JetStream has some latency tests that are meant to measure jitter. Prior to this change, they did this by computing the RMS. But the RMS is a pretty bad metric. The thing that it rewards isn't really the thing that you'd want your browser to do. These RMS-based tests involve taking the geomean of the RMS of some samples and the sample average. The lower the geomean, the better (in the JetStream harness we then invert the scores so that higher is better, but let's ignore that for this discussion and assume that lower is better). Here's an example of how this can go bad. A browser that always computes a task in some horribly long time (say, 1000ms) but never varies that time will perform better than a browser that usually computes the task super quickly (say, 10ms) and sometimes just a little bit less quickly (say, 15ms). The former browser will have an RMS of 0 and an average of 1000. The latter will have a RMS somewhere around 3.5 and an average of 12.5 (assuming equal probability of 10ms and 15ms). The geomean of (0, 1000) is 0. The geomean of (3.5, 12.5) is 6.6. Lower is better, so the former browser scores higher - even though it's obviously never better to have a browser always complete a task in 1000ms when a different browser can do it in 15ms in the worst case. JetStream should not have this pathology. The right way of avoiding it is to replace RMS with some other metric of how bad things get. A good metric is the average of the worst percentile. The worst 1% or the worst 5% would be good things to average. This will catch cases where the VM jittered due to JIT or GC, but it never have the pathology that we end up giving the better score to a VM whose best case is worst than another VM's worst case. For now, this change uses the highest samples above the 95% percentile. I'm not yet sure if that is the best thing - it might include too many scores that are around the best-case performance - but it's certainly better than RMS and it might be good enough to keep. But because of that uncertainty, I'm setting the version to be "1.1-alpha1" to indicate that we aren't ready to release this yet. * JetStream/Octane2/base.js: (.this.Setup.setup.setup): (.this.TearDown.tearDown.tearDown): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.RunSingleBenchmark): * JetStream/Octane2/mandreel.js: (setupMandreel): (updateMandreelStats): (startMandreelTimer): (latencyMandreel): (tearDownMandreel): (RMSMandreel): Deleted. * JetStream/Octane2/splay.js: (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplayTearDown): (SplayRMS): Deleted. * JetStream/create.rb: Canonical link: https://commits.webkit.org/163895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185425 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-10 18:44:50 +00:00
splaySamples.push(pause);
Add JetStream to PerformanceTests https://bugs.webkit.org/show_bug.cgi?id=144024 Rubber-stamped by Filip Pizlo. * JetStream: Added. * JetStream/JetStream-Logo.png: Added. * JetStream/JetStream-Logo@2x.png: Added. * JetStream/JetStream.css: Added. * JetStream/JetStreamDriver.js: Added. * JetStream/LICENSE.txt: Added. * JetStream/LLVM-test-suite-LICENSE.txt: Added. * JetStream/Octane: Added. * JetStream/Octane/base.js: Added. * JetStream/Octane/code-load.js: Added. * JetStream/Octane2: Added. * JetStream/Octane2/base.js: Added. * JetStream/Octane2/box2d.js: Added. * JetStream/Octane2/code-load.js: Added. * JetStream/Octane2/crypto.js: Added. * JetStream/Octane2/deltablue.js: Added. * JetStream/Octane2/earley-boyer.js: Added. * JetStream/Octane2/gbemu-part1.js: Added. * JetStream/Octane2/gbemu-part2.js: Added. * JetStream/Octane2/mandreel.js: Added. * JetStream/Octane2/navier-stokes.js: Added. * JetStream/Octane2/pdfjs.js: Added. * JetStream/Octane2/raytrace.js: Added. * JetStream/Octane2/regexp.js: Added. * JetStream/Octane2/richards.js: Added. * JetStream/Octane2/run.js: Added. * JetStream/Octane2/splay.js: Added. * JetStream/Octane2/typescript-compiler.js: Added. * JetStream/Octane2/typescript-input.js: Added. * JetStream/Octane2/typescript.js: Added. * JetStream/Octane2/zlib-data.js: Added. * JetStream/Octane2/zlib.js: Added. * JetStream/Octane2Setup.js: Added. * JetStream/OctaneSetup.js: Added. * JetStream/README: Added. * JetStream/Reference.js: Added. * JetStream/SimpleSetup.js: Added. * JetStream/SunSpiderSetup.js: Added. * JetStream/Swoosh.png: Added. * JetStream/Swoosh@2x.png: Added. * JetStream/TestingSetup.js: Added. * JetStream/create.rb: Added. * JetStream/docs: Added. * JetStream/docs/JetStreamBlogPost.html: Added. * JetStream/in-depth-TEMPLATE.html: Added. * JetStream/index-TEMPLATE.html: Added. * JetStream/simple: Added. * JetStream/simple/bigfib.cpp: Added. * JetStream/simple/bigfib.cpp.js: Added. * JetStream/simple/container.cpp: Added. * JetStream/simple/container.cpp.js: Added. * JetStream/simple/dry.c: Added. * JetStream/simple/dry.c.js: Added. * JetStream/simple/float-mm.c: Added. * JetStream/simple/float-mm.c.js: Added. * JetStream/simple/gcc-loops.cpp: Added. * JetStream/simple/gcc-loops.cpp.js: Added. * JetStream/simple/hash-map.js: Added. * JetStream/simple/n-body.c: Added. * JetStream/simple/n-body.c.js: Added. * JetStream/simple/quicksort.c: Added. * JetStream/simple/quicksort.c.js: Added. * JetStream/simple/towers.c: Added. * JetStream/simple/towers.c.js: Added. * JetStream/sunspider: Added. * JetStream/sunspider/3d-cube.js: Added. * JetStream/sunspider/3d-raytrace.js: Added. * JetStream/sunspider/base64.js: Added. * JetStream/sunspider/cordic.js: Added. * JetStream/sunspider/crypto-aes.js: Added. * JetStream/sunspider/crypto-md5.js: Added. * JetStream/sunspider/crypto-sha1.js: Added. * JetStream/sunspider/date-format-tofte.js: Added. * JetStream/sunspider/date-format-xparb.js: Added. * JetStream/sunspider/n-body.js: Added. * JetStream/sunspider/regex-dna.js: Added. * JetStream/sunspider/tagcloud.js: Added. Canonical link: https://commits.webkit.org/161992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-22 02:30:22 +00:00
}
function InsertNewNode() {
// Insert new node with a unique key.
var key;
do {
key = GenerateKey();
} while (splayTree.find(key) != null);
var payload = GeneratePayloadTree(kSplayTreePayloadDepth, String(key));
splayTree.insert(key, payload);
return key;
}
function SplaySetup() {
// Check if the platform has the performance.now high resolution timer.
// If not, throw exception and quit.
if (!performance.now) {
throw "PerformanceNowUnsupported";
}
splayTree = new SplayTree();
splaySampleTimeStart = performance.now()
for (var i = 0; i < kSplayTreeSize; i++) {
InsertNewNode();
if ((i+1) % 20 == 19) {
SplayUpdateStats(performance.now());
}
}
}
function SplayTearDown() {
// Allow the garbage collector to reclaim the memory
// used by the splay tree no matter how we exit the
// tear down function.
var keys = splayTree.exportKeys();
splayTree = null;
JetStream should have a more rational story for jitter-oriented latency tests https://bugs.webkit.org/show_bug.cgi?id=145762 Reviewed by Geoffrey Garen. JetStream has some latency tests that are meant to measure jitter. Prior to this change, they did this by computing the RMS. But the RMS is a pretty bad metric. The thing that it rewards isn't really the thing that you'd want your browser to do. These RMS-based tests involve taking the geomean of the RMS of some samples and the sample average. The lower the geomean, the better (in the JetStream harness we then invert the scores so that higher is better, but let's ignore that for this discussion and assume that lower is better). Here's an example of how this can go bad. A browser that always computes a task in some horribly long time (say, 1000ms) but never varies that time will perform better than a browser that usually computes the task super quickly (say, 10ms) and sometimes just a little bit less quickly (say, 15ms). The former browser will have an RMS of 0 and an average of 1000. The latter will have a RMS somewhere around 3.5 and an average of 12.5 (assuming equal probability of 10ms and 15ms). The geomean of (0, 1000) is 0. The geomean of (3.5, 12.5) is 6.6. Lower is better, so the former browser scores higher - even though it's obviously never better to have a browser always complete a task in 1000ms when a different browser can do it in 15ms in the worst case. JetStream should not have this pathology. The right way of avoiding it is to replace RMS with some other metric of how bad things get. A good metric is the average of the worst percentile. The worst 1% or the worst 5% would be good things to average. This will catch cases where the VM jittered due to JIT or GC, but it never have the pathology that we end up giving the better score to a VM whose best case is worst than another VM's worst case. For now, this change uses the highest samples above the 95% percentile. I'm not yet sure if that is the best thing - it might include too many scores that are around the best-case performance - but it's certainly better than RMS and it might be good enough to keep. But because of that uncertainty, I'm setting the version to be "1.1-alpha1" to indicate that we aren't ready to release this yet. * JetStream/Octane2/base.js: (.this.Setup.setup.setup): (.this.TearDown.tearDown.tearDown): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.RunSingleBenchmark): * JetStream/Octane2/mandreel.js: (setupMandreel): (updateMandreelStats): (startMandreelTimer): (latencyMandreel): (tearDownMandreel): (RMSMandreel): Deleted. * JetStream/Octane2/splay.js: (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplayTearDown): (SplayRMS): Deleted. * JetStream/create.rb: Canonical link: https://commits.webkit.org/163895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185425 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-06-10 18:44:50 +00:00
splaySamples = [];
Add JetStream to PerformanceTests https://bugs.webkit.org/show_bug.cgi?id=144024 Rubber-stamped by Filip Pizlo. * JetStream: Added. * JetStream/JetStream-Logo.png: Added. * JetStream/JetStream-Logo@2x.png: Added. * JetStream/JetStream.css: Added. * JetStream/JetStreamDriver.js: Added. * JetStream/LICENSE.txt: Added. * JetStream/LLVM-test-suite-LICENSE.txt: Added. * JetStream/Octane: Added. * JetStream/Octane/base.js: Added. * JetStream/Octane/code-load.js: Added. * JetStream/Octane2: Added. * JetStream/Octane2/base.js: Added. * JetStream/Octane2/box2d.js: Added. * JetStream/Octane2/code-load.js: Added. * JetStream/Octane2/crypto.js: Added. * JetStream/Octane2/deltablue.js: Added. * JetStream/Octane2/earley-boyer.js: Added. * JetStream/Octane2/gbemu-part1.js: Added. * JetStream/Octane2/gbemu-part2.js: Added. * JetStream/Octane2/mandreel.js: Added. * JetStream/Octane2/navier-stokes.js: Added. * JetStream/Octane2/pdfjs.js: Added. * JetStream/Octane2/raytrace.js: Added. * JetStream/Octane2/regexp.js: Added. * JetStream/Octane2/richards.js: Added. * JetStream/Octane2/run.js: Added. * JetStream/Octane2/splay.js: Added. * JetStream/Octane2/typescript-compiler.js: Added. * JetStream/Octane2/typescript-input.js: Added. * JetStream/Octane2/typescript.js: Added. * JetStream/Octane2/zlib-data.js: Added. * JetStream/Octane2/zlib.js: Added. * JetStream/Octane2Setup.js: Added. * JetStream/OctaneSetup.js: Added. * JetStream/README: Added. * JetStream/Reference.js: Added. * JetStream/SimpleSetup.js: Added. * JetStream/SunSpiderSetup.js: Added. * JetStream/Swoosh.png: Added. * JetStream/Swoosh@2x.png: Added. * JetStream/TestingSetup.js: Added. * JetStream/create.rb: Added. * JetStream/docs: Added. * JetStream/docs/JetStreamBlogPost.html: Added. * JetStream/in-depth-TEMPLATE.html: Added. * JetStream/index-TEMPLATE.html: Added. * JetStream/simple: Added. * JetStream/simple/bigfib.cpp: Added. * JetStream/simple/bigfib.cpp.js: Added. * JetStream/simple/container.cpp: Added. * JetStream/simple/container.cpp.js: Added. * JetStream/simple/dry.c: Added. * JetStream/simple/dry.c.js: Added. * JetStream/simple/float-mm.c: Added. * JetStream/simple/float-mm.c.js: Added. * JetStream/simple/gcc-loops.cpp: Added. * JetStream/simple/gcc-loops.cpp.js: Added. * JetStream/simple/hash-map.js: Added. * JetStream/simple/n-body.c: Added. * JetStream/simple/n-body.c.js: Added. * JetStream/simple/quicksort.c: Added. * JetStream/simple/quicksort.c.js: Added. * JetStream/simple/towers.c: Added. * JetStream/simple/towers.c.js: Added. * JetStream/sunspider: Added. * JetStream/sunspider/3d-cube.js: Added. * JetStream/sunspider/3d-raytrace.js: Added. * JetStream/sunspider/base64.js: Added. * JetStream/sunspider/cordic.js: Added. * JetStream/sunspider/crypto-aes.js: Added. * JetStream/sunspider/crypto-md5.js: Added. * JetStream/sunspider/crypto-sha1.js: Added. * JetStream/sunspider/date-format-tofte.js: Added. * JetStream/sunspider/date-format-xparb.js: Added. * JetStream/sunspider/n-body.js: Added. * JetStream/sunspider/regex-dna.js: Added. * JetStream/sunspider/tagcloud.js: Added. Canonical link: https://commits.webkit.org/161992@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-04-22 02:30:22 +00:00
// Verify that the splay tree has the right size.
var length = keys.length;
if (length != kSplayTreeSize) {
throw new Error("Splay tree has wrong size");
}
// Verify that the splay tree has sorted, unique keys.
for (var i = 0; i < length - 1; i++) {
if (keys[i] >= keys[i + 1]) {
throw new Error("Splay tree not sorted");
}
}
}
function SplayRun() {
// Replace a few nodes in the splay tree.
for (var i = 0; i < kSplayTreeModifications; i++) {
var key = InsertNewNode();
var greatest = splayTree.findGreatestLessThan(key);
if (greatest == null) splayTree.remove(key);
else splayTree.remove(greatest.key);
}
SplayUpdateStats(performance.now());
}
/**
* Constructs a Splay tree. A splay tree is a self-balancing binary
* search tree with the additional property that recently accessed
* elements are quick to access again. It performs basic operations
* such as insertion, look-up and removal in O(log(n)) amortized time.
*
* @constructor
*/
function SplayTree() {
};
/**
* Pointer to the root node of the tree.
*
* @type {SplayTree.Node}
* @private
*/
SplayTree.prototype.root_ = null;
/**
* @return {boolean} Whether the tree is empty.
*/
SplayTree.prototype.isEmpty = function() {
return !this.root_;
};
/**
* Inserts a node into the tree with the specified key and value if
* the tree does not already contain a node with the specified key. If
* the value is inserted, it becomes the root of the tree.
*
* @param {number} key Key to insert into the tree.
* @param {*} value Value to insert into the tree.
*/
SplayTree.prototype.insert = function(key, value) {
if (this.isEmpty()) {
this.root_ = new SplayTree.Node(key, value);
return;
}
// Splay on the key to move the last node on the search path for
// the key to the root of the tree.
this.splay_(key);
if (this.root_.key == key) {
return;
}
var node = new SplayTree.Node(key, value);
if (key > this.root_.key) {
node.left = this.root_;
node.right = this.root_.right;
this.root_.right = null;
} else {
node.right = this.root_;
node.left = this.root_.left;
this.root_.left = null;
}
this.root_ = node;
};
/**
* Removes a node with the specified key from the tree if the tree
* contains a node with this key. The removed node is returned. If the
* key is not found, an exception is thrown.
*
* @param {number} key Key to find and remove from the tree.
* @return {SplayTree.Node} The removed node.
*/
SplayTree.prototype.remove = function(key) {
if (this.isEmpty()) {
throw Error('Key not found: ' + key);
}
this.splay_(key);
if (this.root_.key != key) {
throw Error('Key not found: ' + key);
}
var removed = this.root_;
if (!this.root_.left) {
this.root_ = this.root_.right;
} else {
var right = this.root_.right;
this.root_ = this.root_.left;
// Splay to make sure that the new root has an empty right child.
this.splay_(key);
// Insert the original right child as the right child of the new
// root.
this.root_.right = right;
}
return removed;
};
/**
* Returns the node having the specified key or null if the tree doesn't contain
* a node with the specified key.
*
* @param {number} key Key to find in the tree.
* @return {SplayTree.Node} Node having the specified key.
*/
SplayTree.prototype.find = function(key) {
if (this.isEmpty()) {
return null;
}
this.splay_(key);
return this.root_.key == key ? this.root_ : null;
};
/**
* @return {SplayTree.Node} Node having the maximum key value.
*/
SplayTree.prototype.findMax = function(opt_startNode) {
if (this.isEmpty()) {
return null;
}
var current = opt_startNode || this.root_;
while (current.right) {
current = current.right;
}
return current;
};
/**
* @return {SplayTree.Node} Node having the maximum key value that
* is less than the specified key value.
*/
SplayTree.prototype.findGreatestLessThan = function(key) {
if (this.isEmpty()) {
return null;
}
// Splay on the key to move the node with the given key or the last
// node on the search path to the top of the tree.
this.splay_(key);
// Now the result is either the root node or the greatest node in
// the left subtree.
if (this.root_.key < key) {
return this.root_;
} else if (this.root_.left) {
return this.findMax(this.root_.left);
} else {
return null;
}
};
/**
* @return {Array<*>} An array containing all the keys of tree's nodes.
*/
SplayTree.prototype.exportKeys = function() {
var result = [];
if (!this.isEmpty()) {
this.root_.traverse_(function(node) { result.push(node.key); });
}
return result;
};
/**
* Perform the splay operation for the given key. Moves the node with
* the given key to the top of the tree. If no node has the given
* key, the last node on the search path is moved to the top of the
* tree. This is the simplified top-down splaying algorithm from:
* "Self-adjusting Binary Search Trees" by Sleator and Tarjan
*
* @param {number} key Key to splay the tree on.
* @private
*/
SplayTree.prototype.splay_ = function(key) {
if (this.isEmpty()) {
return;
}
// Create a dummy node. The use of the dummy node is a bit
// counter-intuitive: The right child of the dummy node will hold
// the L tree of the algorithm. The left child of the dummy node
// will hold the R tree of the algorithm. Using a dummy node, left
// and right will always be nodes and we avoid special cases.
var dummy, left, right;
dummy = left = right = new SplayTree.Node(null, null);
var current = this.root_;
while (true) {
if (key < current.key) {
if (!current.left) {
break;
}
if (key < current.left.key) {
// Rotate right.
var tmp = current.left;
current.left = tmp.right;
tmp.right = current;
current = tmp;
if (!current.left) {
break;
}
}
// Link right.
right.left = current;
right = current;
current = current.left;
} else if (key > current.key) {
if (!current.right) {
break;
}
if (key > current.right.key) {
// Rotate left.
var tmp = current.right;
current.right = tmp.left;
tmp.left = current;
current = tmp;
if (!current.right) {
break;
}
}
// Link left.
left.right = current;
left = current;
current = current.right;
} else {
break;
}
}
// Assemble.
left.right = current.left;
right.left = current.right;
current.left = dummy.right;
current.right = dummy.left;
this.root_ = current;
};
/**
* Constructs a Splay tree node.
*
* @param {number} key Key.
* @param {*} value Value.
*/
SplayTree.Node = function(key, value) {
this.key = key;
this.value = value;
};
/**
* @type {SplayTree.Node}
*/
SplayTree.Node.prototype.left = null;
/**
* @type {SplayTree.Node}
*/
SplayTree.Node.prototype.right = null;
/**
* Performs an ordered traversal of the subtree starting at
* this SplayTree.Node.
*
* @param {function(SplayTree.Node)} f Visitor function.
* @private
*/
SplayTree.Node.prototype.traverse_ = function(f) {
var current = this;
while (current) {
var left = current.left;
if (left) left.traverse_(f);
f(current);
current = current.right;
}
};