实验方法:连续插入并读出一条KV,
for (count = 1; count < 30000; count++) {
snprintf(key,128,"%010d", count);
snprintf(val,128,"2024-06-07 14:39 %8d", count);
fdb_kv_set(kvdb, key, val);
FDB_INFO("insert [%d]", count);
{ /* GET the KV value */
char *return_value, temp_data2[30] = { 0 };
/* Get the "temp" KV value.
* NOTE: The return value saved in fdb_kv_get's buffer. Please copy away as soon as possible.
*/
return_value = fdb_kv_get(kvdb, key);
/* the return value is NULL when get the value failed */
if (return_value != NULL) {
strncpy(temp_data2, return_value, sizeof(temp_data2));
FDB_INFO("get the value is: %s\n", temp_data2);
}
}
}
在存有1000条时,插入读出一条KV需要38.5ms。
在存有2000条时,插入读出一条KV需要93ms。
部分LOG如下:
[09:58:10.372]收←◆System Clock information
SYSCLK_Frequency = 168000000
HCLK_Frequency = 168000000
PCLK1_Frequency = 42000000
PCLK2_Frequency = 84000000
[09:58:19.027]收←◆[D/FAL] (fal_flash_init:47) Flash device |
[09:58:19.120]收←◆ stm32_onchip | addr: 0x08000000 | len: 0x00100000 | blk_size: 0x00020000 |initialized finish.
[32;22m[I/FAL] ==================== FAL partition table ====================[0m
[32;22m[I/FAL] | name | flash_dev | offset | length |[0m
[32;22m[I/FAL] -------------------------------------------------------------[0m
[32;22m[I/FAL] | fdb_tsdb1 | stm32_onchip | 0x00040000 | 0x00040000 |[0m
[32;22m[I/FAL] | fdb_kvdb1 | stm32_onchip | 0x00080000 | 0x00040000 |[0m
[32;22m[I/FAL] =============================================================[0m
[32;22m[I/FAL] Flash Abstraction Layer (V0.5.99) initialize success.[0m
[FlashDB][kv][env][fdb_kvdb1] (..\..\..\src\fdb_kvdb.c:1777) The oldest addr is @0x00000000
[FlashDB][kv][env][fdb_kvdb1] (..\..\..\src\fdb_kvdb.c:1793) KVDB size is 262144 bytes.
[09:58:19.152]收←◆[FlashDB] FlashDB V2.1.0 is initiali
[09:58:19.191]收←◆ze success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
//
[09:58:29.452]收←◆[FlashDB][sample][kvdb][blob] insert [498][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 498
[09:58:29.478]收←◆[FlashDB][sample][kvdb][blob] insert [499][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 499
[FlashDB][sample][kvdb][blob] insert [500][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 500
[09:58:29.531]收←◆[FlashDB][sample][kvdb][blob] insert [501][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 501
[09:58:29.558]收←◆[FlashDB][sample][kvdb][blob] insert [502][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 502
//
[10:07:53.097]收←◆[FlashDB][sample][kvdb][blob] insert [999][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 999
[10:07:53.135]收←◆[FlashDB][sample][kvdb][blob] insert [1000][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 1000
[10:07:53.174]收←◆[FlashDB][sample][kvdb][blob] insert [1001][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 1001
[10:07:53.213]收←◆[FlashDB][sample][kvdb][blob] insert [1002][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 1002
//
[10:08:43.847]收←◆[FlashDB][sample][kvdb][blob] insert [1999][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 1999
[10:08:43.910]收←◆[FlashDB][sample][kvdb][blob] insert [2000][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 2000
[10:08:43.972]收←◆[FlashDB][sample][kvdb][blob] insert [2001][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 2001
[10:08:44.428]收←◆[FlashDB][sample][kvdb][blob] insert [2002][FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 2002