[OpenLayers-Commits] r5140 - sandbox/ahocevar/sldRenderer/examples
commits at openlayers.org
commits at openlayers.org
Wed Nov 7 06:41:29 EST 2007
Author: ahocevar
Date: 2007-11-07 06:41:27 -0500 (Wed, 07 Nov 2007)
New Revision: 5140
Added:
sandbox/ahocevar/sldRenderer/examples/profilingAttributeName.html
Log:
parsing for attributeNames: new method without replace
Added: sandbox/ahocevar/sldRenderer/examples/profilingAttributeName.html
===================================================================
--- sandbox/ahocevar/sldRenderer/examples/profilingAttributeName.html (rev 0)
+++ sandbox/ahocevar/sldRenderer/examples/profilingAttributeName.html 2007-11-07 11:41:27 UTC (rev 5140)
@@ -0,0 +1,140 @@
+<html>
+ <head>
+ <script src="../lib/firebug/firebug.js"></script>
+ <script>
+
+ var feature = {
+ attributes: {
+ name: "foo"
+ }
+ };
+ var feature2 = {
+ attributes: {
+ name: "foo",
+ age: 20,
+ address: "somewhere",
+ status: "single"
+ }
+ };
+ var feature3 = {
+ attributes: {
+ name: "foo",
+ age: 20,
+ address: "somewhere",
+ status: "single",
+ one: "one",
+ two: "two",
+ three: "three",
+ four: "four",
+ five: "five"
+ }
+ };
+
+ function profile(initialValue, feature) {
+ console.time("andreas' method");
+ var j = 0;
+ while (j < 1000) {
+ var value = initialValue;
+ if (typeof value == "string" && value.indexOf("${") != -1) {
+ var attributes = feature.attributes || feature.data;
+ for (var i in attributes) {
+ value = value.replace("${"+i+"}", attributes[i]);
+ }
+ value = isNaN(value) ? value : parseFloat(value);
+ }
+ j++;
+ }
+ console.log("returned value : " + value);
+ console.timeEnd("andreas' method");
+
+
+ console.time("pierre's method");
+ var j = 0;
+ while (j < 1000) {
+ var value = initialValue;
+
+ if (typeof value == "string" && value.indexOf("${") != -1) {
+ var attributes = feature.attributes || feature.data;
+ var re = /\$\{(\w+)\}/;
+ var a;
+ while (a = re.exec(value)) {
+ value = value.replace(a[0], attributes[a[1]]);
+ }
+ value = isNaN(value) ? value : parseFloat(value);
+ }
+ j++;
+ }
+ console.log("returned value : " + value);
+ console.timeEnd("pierre's method");
+
+
+ console.time("andreas' method 2");
+ var j = 0;
+ while (j < 1000) {
+ var value = initialValue;
+
+ if (typeof value == "string" && value.indexOf("${") != -1) {
+ var attributes = feature.attributes || feature.data;
+ var tokens = value.split(/\$\{|\}/);
+ var newValue = new Array(tokens.length);
+ for (var i=0; i<tokens.length; i++) {
+ if (!tokens[i]) {
+ continue;
+ }
+ newValue[i] = attributes[tokens[i]] ? attributes[tokens[i]] : tokens[i];
+ }
+ value = newValue.join("");
+ value = isNaN(value) ? value : parseFloat(value);
+ }
+ j++;
+ }
+ console.log("returned value : " + value);
+ console.timeEnd("andreas' method 2");
+ }
+
+
+
+ var value = "${name}";
+ console.group(value);
+ console.log("feature");
+ profile(value, feature);
+ console.log("feature2");
+ profile(value, feature2);
+ console.log("feature3");
+ profile(value, feature3);
+ console.groupEnd();
+
+ var value = "name: ${name}, age: ${age}, address: ${address}, status: ${status}";
+ console.group(value);
+ console.log("feature");
+ profile(value, feature);
+ console.log("feature2");
+ profile(value, feature2);
+ console.log("feature3");
+ profile(value, feature3);
+ console.groupEnd();
+
+
+ </script>
+ </head>
+ <body>
+ In this example we test the following cases :
+ <ul>
+ <li>Different values to create a literal with :
+ <ul>
+ <li>simple value : "${name}"</li>
+ <li>more complex value : "name: ${name}, age: ${age}, address: ${somewhere}, status: ${status}"</li>
+ </ul>
+ </li>
+ <li>Different features :
+ <ul>
+ <li>one single attribute</li>
+ <li>4 attributes</li>
+ <li>9 attributes</li>
+ </ul>
+ </li>
+ </ul>
+
+ Each test is made with a 1000 cycles loop.
+ </body>
+</html>
Property changes on: sandbox/ahocevar/sldRenderer/examples/profilingAttributeName.html
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
Name: svn:eol-style
+ native
More information about the Commits
mailing list