F407外部SPI存储器,循环读取一条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);
}
}
}
LOG如下:
[09:23:06.315]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 199
[09:23:06.353]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 200
[09:24:39.214]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 998
[09:24:39.406]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 999
[09:24:39.603]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 1000
[10:03:09.936]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 4998
[10:03:10.920]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 4999
[10:03:11.866]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 5000
[14:37:24.603]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 13999
[14:37:27.296]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 14000
[14:37:29.989]收←◆[FlashDB][sample][kvdb][blob] get the value is: 2024-06-07 14:39 14001
总结:
K较大时,用时较长。原因:因为写入的数据是按K从小到大写入,K大值排在最后面,所以查到时需时较长。
读出第200条时,需时38ms。
读出第1000条时,需时192ms。
读出第5000条时,需时946ms。查询平均一个节点0.189ms。
读出第14000条时,需时2693ms。查询平均一个节点0.192ms。
从第1000条到第14000条(共13000条)用时14:37:27.296 - 09:24:39.603 =18767.693秒(5时 12分 47秒)