Permalink
Browse files

checkpoint - working on perf tests page

  • Loading branch information...
1 parent e113e3e commit c91e2625855e75da28d2e0b7979d987342937d5e @mckoss committed Mar 24, 2011
Showing with 234 additions and 10 deletions.
  1. +4 −2 app.manifest
  2. +1 −0 dicts/ospd3.trie.txt
  3. +58 −0 test/perf-test.html
  4. +153 −0 test/perf-test.js
  5. +18 −8 test/test-trie.js
View
@@ -18,8 +18,8 @@ NETWORK:
# All contents below AUTOGENERATED are managed by pf.py
# Directives starting with '#!' will be preserved.
#!EXCLUDE: dicts
-# TOTAL FILES: 16 (74,655 bytes)
-# SIGNATURE: 9409c1f4974cc6514af84fb48d977971b462ab68
+# TOTAL FILES: 18 (81,320 bytes)
+# SIGNATURE: 37666cf6bc2b77dd1f4e4083547b8815aabd2e2a
CACHE:
README.md
images/gradient.jpg
@@ -34,6 +34,8 @@ scripts/ptrie.js
scripts/ptrie.min.js
scripts/trie.js
styles/main.css
+test/perf-test.html
+test/perf-test.js
test/test-runner-min.html
test/test-runner.html
test/test-trie.js
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html manifest="/app.manifest">
+<head>
+<title>PackedTrie Performance Test</title>
+<link rel="icon" type="image/png" href="/images/icon.png" />
+<link rel="apple-touch-icon" href="/images/touch.png" />
+<link rel="stylesheet" type="text/css" href="/styles/main.css" />
+<link rel="stylesheet" type="text/css" href="/lib/beta/css/client.css" />
+<script type="text/javascript"
+ src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
+<script type="text/javascript" src="/lib/beta/js/json2.min.js"></script>
+<script type="text/javascript" src="/lib/beta/js/utils.js"></script>
+<script type="text/javascript" src="/scripts/ptrie.js"></script>
+<script type="text/javascript" src="perf-test.js"></script>
+
+<script type="text/javascript">
+ $(document).ready(namespace.com.pageforest.trie.packed.test.perf.onReady);
+</script>
+
+</head>
+
+<body>
+ <div id="page">
+ <h1 id="page-heading">
+ <span id="title">Packed Trie Performance Test</span>
+ <span class="menu-bar">
+ <button id="run">Run Perf Test</button>
+ </span>
+ </h1>
+
+ <h2>Log:</h2>
+ <hr/>
+ <ol id="log">
+ </ol>
+
+ <div id="footer">
+ <hr/>
+ <a href="http://ejohn.org/blog/dictionary-lookups-in-javascript/">Dictionary Lookups in JavaScript (John Resig)</a> |
+ <a href="https://github.com/mckoss/lookups">Fork Me on Github</a> |
+ <a href="http://www.pageforest.com">Pageforest.com</a>
+ </div> <!-- footer -->
+
+ </div> <!-- page -->
+
+ <script type="text/javascript">
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-2072869-7']);
+ _gaq.push(['_trackPageview']);
+
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +
+ '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ </script>
+</body>
+</html>
View
@@ -0,0 +1,153 @@
+/*globals applicationCache */
+namespace.lookup('com.pageforest.trie.packed.test.perf').defineOnce(function(ns) {
+ var dom = namespace.lookup('org.startpad.dom');
+ var base = namespace.lookup('org.startpad.base');
+ var format = namespace.lookup('org.startpad.format');
+ var trieLib = namespace.lookup('org.startpad.trie');
+ var ptrieLib = namespace.lookup('org.startpad.trie.packed');
+
+ ns.extend({
+ 'onReady': onReady,
+ 'getDoc': getDoc,
+ 'getDocid': getDocid,
+ 'setDocid': function () {}
+ });
+
+ var client;
+ var rawDictionary;
+ var trie;
+ var ptrie;
+ var words;
+ var tasks = [];
+ var timedResults = {};
+ var doc; // Bound elements here
+ var DOCID = 'perf-test';
+ var BLOBID = 'results';
+
+ function handleAppCache() {
+ if (typeof applicationCache == 'undefined') {
+ return;
+ }
+
+ if (applicationCache.status == applicationCache.UPDATEREADY) {
+ applicationCache.swapCache();
+ location.reload();
+ return;
+ }
+
+ applicationCache.addEventListener('updateready', handleAppCache, false);
+ }
+
+ function log(s) {
+ $(doc.log).append('<li>' + format.escapeHTML(s) + '</li>');
+ }
+
+ function timedTasks(tasks, fn) {
+ var iNext = 0, msLast;
+
+ function next() {
+ if (iNext != 0) {
+ var time = new Date().getTime() - msLast;
+ task = tasks[iNext - 1];
+ timedResults[task.key] = time;
+ log("Complete: " + task.message + ' (' + format.thousands(time) + ' ms)');
+ }
+ if (iNext >= tasks.length) {
+ fn();
+ return;
+ }
+
+ task = tasks[iNext++];
+ msLast = new Date().getTime();
+ log("Starting: " + task.message);
+ if (!task.fn(next)) {
+ next();
+ }
+ }
+
+ next();
+ }
+
+
+ function task(key, message, fn) {
+ tasks.push({key: key, message: message, fn: fn});
+ }
+
+ task('dict-load',
+ "Load Dictionary",
+ function (fn) {
+ $.ajax('/dicts/ospd3.txt', {success: function (result) {
+ rawDictionary = result;
+ words = rawDictionary.split('\n');
+ fn();
+ }});
+ return true;
+ });
+
+ task('ptrie-load', "Load Packed Trie File",
+ function (fn) {
+ $.ajax('/dicts/ospd3.trie.txt', {success: function (result) {
+ ptrie = new ptrieLib.PackedTrie(result);
+ fn();
+ }});
+ return true;
+ });
+
+ task('ptrie-lookups', "Lookup 1,000 words in PackedTrie",
+ function (fn) {
+ var skip = Math.floor(words.length / 1000);
+ for (var i = 0; i < words.length; i += skip) {
+ ptrie.isWord(words[i]);
+ }
+ });
+
+ task('trie-create', "Create Trie From Full Dictionary",
+ function (fn) {
+ trie = new trieLib.Trie(rawDictionary);
+ });
+
+ task('trie-lookups', "Lookup 1,000 words in Trie",
+ function (fn) {
+ var skip = Math.floor(words.length / 1000);
+ for (var i = 0; i < words.length; i += skip) {
+ trie.isWord(words[i]);
+ }
+ });
+
+ function getDocid() {
+ return DOCID;
+ }
+
+ function getDoc() {
+ return {
+ docid: DOCID,
+ blob: {version: 1},
+ readers: ['public']
+ };
+ }
+
+ function saveResults() {
+ result.browser = base.project(navigator, ['appVersion', 'platform', 'vendor']);
+ result.date = new Date();
+ if (client.username) {
+ client.storage.push(DOCID, BLOBID, result, undefined, function() {
+ log("Results Saved");
+ });
+ } else {
+ log("Signin to Pageforest to have your results recorded!");
+ }
+ }
+
+ function onReady() {
+ handleAppCache();
+ doc = dom.bindIDs();
+ client = new namespace.com.pageforest.client.Client(ns);
+ client.saveInterval = 0;
+ client.addAppBar();
+
+ $(doc.run).click(function () {
+ timedTasks(tasks, saveResults);
+ });
+ }
+
+});
View
@@ -199,6 +199,7 @@ namespace.lookup('org.startpad.trie.test').defineOnce(function (ns) {
var word, i, trie, ptrie, pack;
var words = ['almond', 'almonds', 'as', 'the', 'and',
'battle', 'battles'];
+ var ms, msLast;
$.ajax('/dicts/ospd3.txt', {
success: function (result) {
@@ -223,24 +224,33 @@ namespace.lookup('org.startpad.trie.test').defineOnce(function (ns) {
words.pop();
ut.assertEq(words.length, 80612, "dictionary assumed length");
- var msStart = new Date().getTime();
+ msLast = new Date().getTime();
+ var calls = 0;
for (i = 0; i < words.length; i += 100) {
word = words[i];
ut.assert(trie.isWord(word), word + " in Trie");
+ calls++;
}
- var calls = 0;
- msTrie = new Date().getTime();
+ ms = new Date().getTime();
+ console.log("Calls: " + calls);
+ console.log("Trie lookup avg: " +
+ (ms - msLast) / calls);
+ msLast = ms;
for (i = 0; i < words.length; i += 100) {
word = words[i];
ut.assert(ptrie.isWord(word), word + " in PackedTrie");
- calls++;
}
- msPTrie = new Date().getTime();
+ ms = new Date().getTime();
- console.log("Trie lookup avg: " +
- (msTrie - msStart) / calls);
console.log("PackedTrie lookup avg: " +
- (msPTrie - msTrie) / calls);
+ (ms - msLast) / calls);
+
+ msLast = ms;
+ for (i = 0; i < 1000; i++) {
+ ptrie.isWord('battle');
+ }
+ ms = new Date().getTime();
+ console.log("battle: " + (ms - msLast) / 1000);
ut.async(false);

0 comments on commit c91e262

Please sign in to comment.