[Qgis-developer] Benchmarking QgsExpression against V8

Alister Hood alister.hood at synergine.com
Mon Jan 9 22:05:25 EST 2012


Hi,

I think the language for expressions should be considered carefully.  It
can have a fairly big impact on user experience, particularly for people
who aren't programmers.

What other candidates might there be?  How do they compare in terms of
intuitiveness?  The less time people need to spend reading the help
every time they build an expression, the better.

Alister

> Date: Tue, 10 Jan 2012 01:00:11 +0100
> From: Pirmin Kalberer <pi_ml at sourcepole.com>
> Subject: [Qgis-developer] Benchmarking QgsExpression against V8
> To: qgis-developer at lists.osgeo.org
> Message-ID: <2052129.lmK783bSmN at polarwind2>
> Content-Type: text/plain; charset="us-ascii"
> 
> Hi all,
> 
> Following the recent enhancements of QGsExpression, I was wondering
> whether it
> wouldn't make sense to integrate a language intepreter instead of
> creating
> another language.
> One candidate would be Google's V8 JavaScript engine
> (http://code.google.com/p/v8/). Since embedding this C++ library is
> easy, I've
> conducted a few quick benchmarks against QgsExpression. Code is
> attached.
> 
> Test 1:
> Qgs: '1' || '2' || '3' || '4' || '5' || '6' || '7' || '8' || '9' ||
'0'
> total_avg: 3.380211
> V8: '1' + '2' + '3' + '4' + '5' + '6' + '7' + '8' + '9' + '0'
> total_avg: 0.556035
> Fact: 6.0791335
> 
> Test 2:
> Qgs: 1+1=2 AND 5>1
> total_avg: 4.072254
> V8: 1+1==2 && 5>4
> total_avg: 0.864054
> Fact: 4.7129624
> 
> Test 3:
> Qgs: replace(lower( 'AAAAAAAAAAxxCCCCCCCC'), 'xx', 'BB')
> total_avg: 3.480217
> V8: 'AAAAAAAAAAxxCCCCCCCC'.toLowerCase().replace('xx', 'BB')
> total_avg: 0.856053
> Fact: 4.0654224
> 
> Test 4:
> Qgs: regexp_replace( 'AAAAAAAAAAxxCCCCCCCC', 'x+', 'b')
> total_avg: 2.952184
> V8: 'AAAAAAAAAAxxCCCCCCCC'.replace(/x+/, 'b')
> total_avg: 0.668042
> Fact: 4.4191593
> 
> Test 5:
> Qgs: CASE WHEN (15 = 11 or 15 = 13 or 15 = 15 or 15 = 21) THEN 15 END
> total_avg: 1.4664916
> V8: if ([11,13,15,21].indexOf(15)>=0) { 15 }
> total_avg: 0.2672168
> Fact: 5.4880217
> 
> This benchmarks show that QgsExpression evaluation is between 4 to 6
> times
> slower than V8. This is much better than I expected, but it's still
> factor 4
> to 6...
> So I think it's worth discussing pros and cons of using V8 as an
> expression
> engine. I see the following points:
> 
> Pros:
> -Better performance
> -Full Javascript language set included
> -Possibility for writing custum functions
> 
> Cons:
> -New language for expressions
> -More fat (3.7MB for libv8.so)
> 
> V8 would be a new runtime dependency but would replace the flex and
> yacc build
> dependencies.
> 
> Any other points?
> 
> Regards
> Pirmin


More information about the Qgis-developer mailing list