sql.js vs alasql.js

JavaScript performance comparison

Revision 9 of this test case created by Mathiasrw

Preparation code

<script src="https://cdn.jsdelivr.net/alasql/0.1/alasql.min.js"></script>
<script src="https://cdn.rawgit.com/kripken/sql.js/master/js/sql.js"></script>


<script>
var NUM_TESTS = 100;

// Generate SQL statements
var sqls = [
  'DROP TABLE IF EXISTS test1',
  'DROP TABLE IF EXISTS test2',
  'CREATE TABLE test1 (one INT, two INT)',
  'CREATE TABLE test2 (two INT, three INT)',
  'CREATE INDEX index_a ON test1 (one)',
  'CREATE INDEX index_b ON test1 (two)',
  'CREATE INDEX index_c ON test2 (two)',
  'CREATE INDEX index_e ON test2 (three)'
];

for (var i = 0; i < NUM_TESTS; i++) {
  sqls.push('INSERT INTO test1 VALUES (' + i % 10 + ',' + ((i * i) % 10) + ')');
  sqls.push('INSERT INTO test2 VALUES (' + i % 10 + ',' + ((i * i) % 10) + ')');
}
</script>


      
<script>
Benchmark.prototype.setup = function() {
  // Prepare SQL.JS database
  var sdb = new SQL.Database();
  sqls.forEach(function(sql) {
    sdb.exec(sql);
  });
  
  
  // Prepare ALASQL.JS database
  var adb = new alasql.Database();
  sqls.forEach(function(sql) {
    adb.exec(sql);
  });
  
  // Query trying to avoid any caching of results
  var salt = 1
  var query = function (){
    return 'SELECT '
           + salt++
           +', SUM(test1.one) AS sumone, test1.two, test2.three '
           +'FROM test1 JOIN test2 ON test1.two = test2.two  '
           +'WHERE test1.one > 5  '
           +'GROUP BY test1.two, test2.three  '
           +'ORDER BY three, sumone';
  }

};
</script>

Preparation code output

<script src="https://cdn.rawgit.com/kripken/sql.js/master/js/sql.js"></script> <script> var NUM_TESTS = 100; // Generate SQL statements var sqls = [ 'DROP TABLE IF EXISTS test1', 'DROP TABLE IF EXISTS test2', 'CREATE TABLE test1 (one INT, two INT)', 'CREATE TABLE test2 (two INT, three INT)', 'CREATE INDEX index_a ON test1 (one)', 'CREATE INDEX index_b ON test1 (two)', 'CREATE INDEX index_c ON test2 (two)', 'CREATE INDEX index_e ON test2 (three)' ]; for (var i = 0; i < NUM_TESTS; i++) { sqls.push('INSERT INTO test1 VALUES (' + i % 10 + ',' + ((i * i) % 10) + ')'); sqls.push('INSERT INTO test2 VALUES (' + i % 10 + ',' + ((i * i) % 10) + ')'); } </script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
sql.js
sdb.exec(query());
pending…
alasql.js
adb.exec(query());
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments