[OpenLayers-Commits] r5139 - sandbox/camptocamp/text/examples
commits at openlayers.org
commits at openlayers.org
Wed Nov 7 05:09:07 EST 2007
Author: pgiraud
Date: 2007-11-07 05:09:03 -0500 (Wed, 07 Nov 2007)
New Revision: 5139
Added:
sandbox/camptocamp/text/examples/regex.html
Log:
file to make bench on regex for createLiteral method
Added: sandbox/camptocamp/text/examples/regex.html
===================================================================
--- sandbox/camptocamp/text/examples/regex.html (rev 0)
+++ sandbox/camptocamp/text/examples/regex.html 2007-11-07 10:09:03 UTC (rev 5139)
@@ -0,0 +1,114 @@
+<html>
+ <head>
+ <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");
+ }
+
+
+ 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>
\ No newline at end of file
More information about the Commits
mailing list