C++ Map (compiled to WebAssembly) vs JavaScript Map

In my previous post, I talked about WebAssembly (WASM) and its potential through the eyes of a JavaScript web developer. (I recommend reading that post before this one)

After writing my post I was excited to use WASM in a real application I was developing at my internship at GDK Software. I was not developing applications with real heavy calculations so there wasn’t a proper use for WASM, but that did not slow me down in using this new technology.

Converting a MySQL database to an MSSQL database

One application I was working on was a Node.Js script that converts a MySQL database to an MSSQL database. Because MySQL can use an unsigned int as a datatype for identifier it was not possible to just straight up copy this field. For this purpose, I added a new column to the tables in the MSSQL database that would hold the original identifier from the MySQL database.

Every time I needed a foreign key constraint I would look up the new identifier using the original identifier. This meant a constant flow of select statements to the MSSQL database.


Instead of asking the MSSQL database for the new identifier I thought I should make a local map with the original identifier as the key and the new identifier as the value. So that is exactly what I did and to make it more fun I decided to compare the JavaScript map against the C++ map (compiled to WASM).


Creating a map doesn’t require any additional libraries to be imported.


In C++ no additional libraries are needed as well. Because map is included in the standard library.


So before implementing any map in this conversion, it took the application 324888.4994ms or 325 seconds to convert the database.

To test the performance of both the C++ map and the JavaScript map I took both implementations and run the full conversion 5 times. After which I took the average and compared the two to each other. Here are the results.

JavaScript Map
1.     165171.625ms
2. 163065.303ms
3. 158581.745ms
4. 163711.380ms
5. 160601.130ms
Average: 162226.2366ms
C++ Map
1.     163367.855ms
2. 161873.929ms
3. 158132.038ms
4. 159239.384ms
5. 161082.063ms
Average: 160739.0538ms

So implementing a map, in general, did improve my overall performance of the application. But did WASM improve the application… Well, it did with about 1.5 seconds. Which isn’t much of an improvement.


I did not really expect a big improvement because map is not relying on heavy calculations. It was however fun to implement some C++ in my Node.Js. WASM gives developers the opportunity to write different code than just JavaScript in their application without any performance drawbacks (and even a slight performance improvement in this case).