Benchmarks

January 8, 2025 ยท View on GitHub

Table of Contents

Overview

  • :warning: This benchmark is an initial version and it can certainly be greatly improved to make the results as relevant as possible. Feel free to open issues to improve it.
  • :point_right: Native DB will be further improved in the future as performance issues have not yet been addressed. That is indeed the purpose of this benchmark, which is to provide visibility on what needs to be improved.

Comparison between Native DB vs Redb vs SQLite

  • Why compare with Redb?
    • To highlight the Native DB overhead, because Redb is the backend of Native DB, it should "normally" always be faster than Native DB.
  • Why compare with SQLite?
    • Because even though SQLite offers a lot more options, Native DB can be seen as a very light alternative to SQLite.
  • And the other databases?
    • Knowing the capabilities of Native DB compared to Redb with the benchmark below, you can check the benchmark of redb here: cberner/redb/benchmarks

The benchmarks ignore:

  • native_model overhead.
  • Serialization overhead used by native_model like bincode,postcard etc.
  • The fact that redb can write the data using zero-copy.

Explanation:

  • 1:SK, 10:SK, 50:SK, 100:SK, N:SK in this case N is the number of secondary keys (SK) for the same data. Regarding SQLite, it is the column with each having a secondary index.
  • 1:T, n:T represent the number of operations per transaction.
    • 1:T means one operation per transaction, for example, for insertion, it means there is only one insert operation per transaction.
    • n:T means n operations per transaction, n is defined by criterion, meaning that all operations are within a single transaction.
  • We can see that Redb sometimes has no comparisons (N/A) because Redb is a key-value database and does not support secondary indexes. Therefore, it is pointless to compare with more or fewer secondary indexes.

Benchmark Results

Insert

Native_dbNative_db_twophasecommitNative_db_quickrepairRedbSqlite
1:SK with n:T5.36 us (โœ… 1.00x)5.42 us (โœ… 1.01x slower)5.37 us (โœ… 1.00x slower)1.09 us (๐Ÿš€ 4.90x faster)1.68 us (๐Ÿš€ 3.19x faster)
1:SK with 1:T33.43 us (โœ… 1.00x)428.91 us (โŒ 12.83x slower)33.31 us (โœ… 1.00x faster)15.66 us (๐Ÿš€ 2.13x faster)47.86 us (โŒ 1.43x slower)
10:SK with n:T31.21 us (โœ… 1.00x)31.36 us (โœ… 1.00x slower)31.08 us (โœ… 1.00x faster)N/A3.38 us (๐Ÿš€ 9.25x faster)
10:SK with 1:T136.49 us (โœ… 1.00x)525.33 us (โŒ 3.85x slower)139.00 us (โœ… 1.02x slower)N/A50.10 us (๐Ÿš€ 2.72x faster)
50:SK with n:T149.93 us (โœ… 1.00x)149.58 us (โœ… 1.00x faster)148.39 us (โœ… 1.01x faster)N/A16.35 us (๐Ÿš€ 9.17x faster)
50:SK with 1:T537.67 us (โœ… 1.00x)899.42 us (โŒ 1.67x slower)539.79 us (โœ… 1.00x slower)N/A66.48 us (๐Ÿš€ 8.09x faster)
100:SK with n:T294.09 us (โœ… 1.00x)291.53 us (โœ… 1.01x faster)291.70 us (โœ… 1.01x faster)N/A44.57 us (๐Ÿš€ 6.60x faster)
100:SK with 1:T916.36 us (โœ… 1.00x)1.23 ms (โŒ 1.34x slower)923.44 us (โœ… 1.01x slower)N/A98.20 us (๐Ÿš€ 9.33x faster)

Get

Native_dbNative_db_twophasecommitNative_db_quickrepairRedbSqlite
1:SK960.70 ns (โœ… 1.00x)960.34 ns (โœ… 1.00x faster)957.75 ns (โœ… 1.00x faster)492.15 ns (๐Ÿš€ 1.95x faster)1.99 us (โŒ 2.07x slower)
10:SK2.49 us (โœ… 1.00x)2.50 us (โœ… 1.00x slower)2.50 us (โœ… 1.01x slower)N/A3.34 us (โŒ 1.34x slower)
50:SK113.49 us (โœ… 1.00x)112.27 us (โœ… 1.01x faster)114.37 us (โœ… 1.01x slower)N/A21.13 us (๐Ÿš€ 5.37x faster)
100:SK241.06 us (โœ… 1.00x)265.73 us (โœ… 1.10x slower)246.91 us (โœ… 1.02x slower)N/A49.21 us (๐Ÿš€ 4.90x faster)

Select Range Secondary Key

Native_dbNative_db_twophasecommitNative_db_quickrepairSqlite
1:SK value range1.88 ms (โœ… 1.00x)1.88 ms (โœ… 1.00x faster)1.91 ms (โœ… 1.02x slower)706.00 us (๐Ÿš€ 2.66x faster)
10:SK value range2.10 ms (โœ… 1.00x)2.06 ms (โœ… 1.02x faster)2.06 ms (โœ… 1.02x faster)1.35 ms (โœ… 1.55x faster)
50:SK value range5.02 ms (โœ… 1.00x)4.65 ms (โœ… 1.08x faster)4.66 ms (โœ… 1.08x faster)4.64 ms (โœ… 1.08x faster)
100:SK value range6.99 ms (โœ… 1.00x)7.02 ms (โœ… 1.00x slower)6.92 ms (โœ… 1.01x faster)8.55 ms (โŒ 1.22x slower)
1:SK random range1.90 ms (โœ… 1.00x)1.87 ms (โœ… 1.01x faster)1.92 ms (โœ… 1.01x slower)758.63 us (๐Ÿš€ 2.50x faster)
10:SK random range2.15 ms (โœ… 1.00x)2.06 ms (โœ… 1.04x faster)2.10 ms (โœ… 1.02x faster)1.37 ms (โœ… 1.56x faster)
50:SK random range4.43 ms (โœ… 1.00x)4.32 ms (โœ… 1.03x faster)4.30 ms (โœ… 1.03x faster)4.89 ms (โœ… 1.10x slower)
100:SK random range5.47 ms (โœ… 1.00x)8.25 ms (โŒ 1.51x slower)6.21 ms (โŒ 1.14x slower)9.80 ms (โŒ 1.79x slower)

Delete

:warning: We can see that when all operations are in a single transaction (n:T), Native DB has a huge overhead. An issue has been created to resolve this problem #256.

Native_dbNative_db_twophasecommitNative_db_quickrepairRedbSqlite
1:SK with n:T6.00 us (โœ… 1.00x)5.99 us (โœ… 1.00x faster)6.07 us (โœ… 1.01x slower)1.15 us (๐Ÿš€ 5.22x faster)1.23 us (๐Ÿš€ 4.90x faster)
1:SK with 1:T30.76 us (โœ… 1.00x)30.75 us (โœ… 1.00x faster)31.38 us (โœ… 1.02x slower)14.65 us (๐Ÿš€ 2.10x faster)46.96 us (โŒ 1.53x slower)
10:SK with n:T36.93 us (โœ… 1.00x)37.24 us (โœ… 1.01x slower)37.18 us (โœ… 1.01x slower)N/A1.39 us (๐Ÿš€ 26.60x faster)
10:SK with 1:T129.28 us (โœ… 1.00x)127.75 us (โœ… 1.01x faster)131.43 us (โœ… 1.02x slower)N/A47.85 us (๐Ÿš€ 2.70x faster)
50:SK with n:T176.44 us (โœ… 1.00x)174.57 us (โœ… 1.01x faster)177.47 us (โœ… 1.01x slower)N/A1.79 us (๐Ÿš€ 98.42x faster)
50:SK with 1:T501.98 us (โœ… 1.00x)501.80 us (โœ… 1.00x faster)501.82 us (โœ… 1.00x faster)N/A51.22 us (๐Ÿš€ 9.80x faster)
100:SK with n:T349.38 us (โœ… 1.00x)350.17 us (โœ… 1.00x slower)349.73 us (โœ… 1.00x slower)N/A2.36 us (๐Ÿš€ 148.25x faster)
100:SK with 1:T862.53 us (โœ… 1.00x)841.21 us (โœ… 1.03x faster)851.42 us (โœ… 1.01x faster)N/A54.53 us (๐Ÿš€ 15.82x faster)

Made with criterion-table