[C#] 一個輕量化的Database - LiteDB 中索引 ( index ) 的相關測試

2024-02-05

今天主要不是寫程式,主要是測試 LiteDB 到底對於索引的處理結果,我這邊有三個測試 collection

FRIEND1- 一百萬的資料沒有做索引

FRIEND2- 前50 萬筆建立好後,製作索引,後面再寫入 50萬筆

FRIEND3- 一百萬筆資料建立好後,再建立索引



我知道在正常情況下,你是用 SQL Server 你對某張 Table 建立索引某欄位索引後,基本上之後就會有索引的功效

但是,LiteDB  是一個 NoSQL 架構的東西,再加上他是一個套件 base 的 DB ,這時候我就好奇到底結果是啥

關於建立索引 可以參考我這篇文章

這邊直接給結果


搜尋的 CODE:


Result:


FRIEND1 -No Index

Cost time:00:00:05.6197011

Count:19

Cost time:00:00:04.3512835

Count:19

Cost time:00:00:04.4416665

Count:19

Cost time:00:00:04.2916714

Count:19

Cost time:00:00:04.2452859

Count:19

Cost time:00:00:04.2105793

Count:19

Cost time:00:00:04.4872268

Count:19

Cost time:00:00:04.2228795

Count:19

Cost time:00:00:04.2496372

Count:19

Cost time:00:00:04.4406661

Count:19

--------------------------------------------------


FRIEND2 -Half Index

Cost time:00:00:01.3297598

Count:19

Cost time:00:00:01.1551111

Count:19

Cost time:00:00:01.1932829

Count:19

Cost time:00:00:01.3067887

Count:19

Cost time:00:00:01.1906908

Count:19

Cost time:00:00:01.2835957

Count:19

Cost time:00:00:01.1776809

Count:19

Cost time:00:00:01.3952630

Count:19

Cost time:00:00:01.2302142

Count:19

Cost time:00:00:01.2056005

Count:19

--------------------------------------------------


FRIEND3 -All Index

Cost time:00:00:01.2406767

Count:19

Cost time:00:00:01.3009102

Count:19

Cost time:00:00:01.2010493

Count:19

Cost time:00:00:01.2404739

Count:19

Cost time:00:00:01.2047526

Count:19

Cost time:00:00:01.4057148

Count:19

Cost time:00:00:01.2531256

Count:19

Cost time:00:00:01.2084465

Count:19

Cost time:00:00:01.2208371

Count:19

Cost time:00:00:01.1915381

Count:19


結論: FRIEND2 跟 FRIEND3 搜尋速度差不多,製作過之後,基本上後面資料都會有製作索引,當然我相信相對的寫入速度可能會慢點,這篇雖然無聊但是花我很多時間

這邊我就沒有測試了。


當麻許的超技八 2014 | Donma Hsu Design.