[OpenLayers-Dev] createLiteral benchs
Pierre GIRAUD
bluecarto at gmail.com
Wed Nov 7 05:45:57 EST 2007
Hello all,
Andreas and I worked on different things yesterday but with a common
need to get a functionality that allows to convert strings including
variable elements ("text + ${propertyName} + text" for example) into
literal strings with some feature attribute values.
Andreas finally wrote a createLiteral method available in both the
ahocevar/sldRenderer and camptocamp/text sandboxes.
I proposed him a patch for this method to make the most of regexp. He
gladly accepted this patch but also asked for benchs to be sure that
my method is better because he knows that regex execution is slow in
JS.
This is what I did, and the results are instructive. Comments below
and test HTML file should be available at
http://dev.openlayers.org/sandbox/camptocamp/text/examples/regex.html.
The Andreas method is better when it deals with features including few
attributes. My method isn't impacted by the number of attributes.
Though, when the string contains several variables to replace, my
method seem to have a better performance later.
In my opinion, it's really odd to have a code closely dependent to the
number of attributes. What if the user loads a GML file with features
having 20 attributes, which might be usually the case ?
Moreover, in most cases, user will want to replace only one single
variable in the string. In that case, my method is not the best only
when the feature has one single attribute.
But, the "while" statement is probably not the best implementation.
Andreas was surprised seeing it. If regex gurus can have a look, I
would be really pleased.
The reason I did that is because the number of variables is not known
before. There might be a better and simpler way to do that.
One more question : do we need to test it in IE too ?
--------------------------------------
benchmark results :
${name}
feature
returned value : foo
andreas' method: 30ms
returned value : foo
pierre's method: 42ms
feature2
returned value : foo
andreas' method: 71ms
returned value : foo
pierre's method: 40ms
feature3
returned value : foo
andreas' method: 149ms
returned value : foo
pierre's method: 41ms
regex.html (line 72)
name: ${name}, age: ${age}, address: ${address}, status: ${status}
feature
returned value : name: foo, age: ${age}, address: ${address},
status: ${status}
andreas' method: 32ms
returned value : name: foo, age: undefined, address: undefined,
status: undefined
pierre's method: 155ms
feature2
returned value : name: foo, age: 20, address: somewhere, status: single
andreas' method: 114ms
returned value : name: foo, age: 20, address: somewhere, status: single
pierre's method: 148ms
feature3
returned value : name: foo, age: 20, address: somewhere, status: single
andreas' method: 595ms
returned value : name: foo, age: 20, address: somewhere, status: single
pierre's method: 149ms
More information about the Dev
mailing list