[Qgis-developer] Benchmarking QgsExpression against V8

Pirmin Kalberer pi_ml at sourcepole.com
Mon Jan 9 19:00:11 EST 2012


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

-- 
Pirmin Kalberer
Sourcepole  -  Linux & Open Source Solutions
http://www.sourcepole.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-V8-benchmark.patch
Type: text/x-patch
Size: 7227 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120110/795aee09/0001-V8-benchmark-0001.bin


More information about the Qgis-developer mailing list