Skip to content

Speed test

Kiran Reddy edited this page Nov 19, 2020 · 5 revisions

Import Module

Import-Module PSLiteDB

Create database

$dbPath = "C:\temp\LiteDB\speedtest.db"
New-LiteDBDatabase -Path $dbPath -Verbose

Connect database

Open-LiteDBConnection -Database $dbPath

Create a collection.

New-LiteDBCollection -Collection P1

Verify collection creation.

Get-LiteDBCollectionName

Start timing the conversion

$time_bsonconversion = [System.Diagnostics.Stopwatch]::new()
$time_bsonconversion.Start()

Insert 30000 records

$array = 1..30000 | ForEach-Object {
    [PSCustomObject]@{
        FirstName = "user-{0}" -f $_
        LastName  = "lastname-{0}" -f $_
        Age       = $_
        Date      = Get-Date
        Long      = (Get-Date).Ticks

    }
} | ConvertTo-LiteDBBSON -As Array

Stop timing conversion

$time_bsonconversion.Stop()

Start timing for insert

$time_bsonInsert = [System.Diagnostics.Stopwatch]::new()
$time_bsonInsert.Start()

Bulk insert 10,000 documents per batch

Add-LiteDBDocument -Collection P1 -BsonDocumentArray $array -BatchSize 10000 -BulkInsert

Stop timing insert

$time_bsonInsert.Stop()

view results

$time_bsonconversion
$time_bsonInsert

Time to Convert 30,000 PSObjects to BSON = 1 min 35 seconds

Time to insert 30,000 BSON Documents = 1 second 👌