前言 本开发板带8GB EMMC,可以作为文件存储使用。作为网关,终端等产品开发时少不了需要数据库的支持,这一篇我们就基于sqlite进行数据库开发的体验。 数据库的性能综合反映了CPU性能,存储IO性能,所以我们后面也对开发板上运行sqlite进行性能测试。
过程
从以下地址下载源码https://www.sqlite.org/2022/sqlite-amalgamation-3400000.zip 解压得到以下文件
- sqlite-amalgamation-3400000
- ├── shell.c
- ├── sqlite
- ├── sqlite3.c
- ├── sqlite3.h
- └── sqlite3ext.h
复制代码
编译 aarch64-linux-gnu-gcc sqlite3.c shell.c -o sqlite -lpthread -ldl 生成可执行文件sqlite 导入到开发板 添加可执行权限 chmod +x sqlite 运行./sqlite
- root@g2uliot:~# ./sqlite
- SQLite version 3.40.0 2022-11-16 12:10:08
- Enter ".help" for usage hints.
- Connected to a transient in-memory database.
- Use ".open FILENAME" to reopen on a persistent database.
- sqlite>
复制代码
性能测试git clone https://github.com/sqlite/sqlite.git test/speedtest1.c程序估计典型工作负载下SQLite的性能。 将speedtest1.c复制到上面的源码路径,一起编译 aarch64-linux-gnu-gcc sqlite3.c speedtest1.c -o speedtest1 -lpthread -ldl 导入 speedtest1到开发板, 添加可执行权限 chmod +x speedtest1 运行
- root@g2uliot:~# ./speedtest1
- -- Speedtest1 for SQLite 3.40.0 2022-11-16 12:10:08 89c459e766ea7e9165d0beeb1247
- 100 - 50000 INSERTs into table with no index...................... 0.755s
- 110 - 50000 ordered INSERTS with one index/PK..................... 1.250s
- 120 - 50000 unordered INSERTS with one index/PK................... 1.557s
- 130 - 25 SELECTS, numeric BETWEEN, unindexed...................... 1.386s
- 140 - 10 SELECTS, LIKE, unindexed................................. 1.584s
- 142 - 10 SELECTS w/ORDER BY, unindexed............................ 2.602s
- 145 - 10 SELECTS w/ORDER BY and LIMIT, unindexed.................. 1.363s
- 150 - CREATE INDEX five times..................................... 1.989s
- 160 - 10000 SELECTS, numeric BETWEEN, indexed..................... 1.200s
- 161 - 10000 SELECTS, numeric BETWEEN, PK.......................... 1.215s
- 170 - 10000 SELECTS, text BETWEEN, indexed........................ 2.696s
- 180 - 50000 INSERTS with three indexes............................ 2.433s
- 190 - DELETE and REFILL one table................................. 2.462s
- 200 - VACUUM...................................................... 1.799s
- 210 - ALTER TABLE ADD COLUMN, and query........................... 0.070s
- 230 - 10000 UPDATES, numeric BETWEEN, indexed..................... 1.153s
- 240 - 50000 UPDATES of individual rows............................ 2.049s
- 250 - One big UPDATE of the whole 50000-row table................. 0.241s
- 260 - Query added column after filling............................ 0.071s
- 270 - 10000 DELETEs, numeric BETWEEN, indexed..................... 3.697s
- 280 - 50000 DELETEs of individual rows............................ 2.545s
- 290 - Refill two 50000-row tables using REPLACE................... 5.544s
- 300 - Refill a 50000-row table using (b&1)==(a&1)................. 2.375s
- 310 - 10000 four-ways joins....................................... 5.533s
- 320 - subquery in result set...................................... 8.320s
- 400 - 70000 REPLACE ops on an IPK................................. 1.680s
- 410 - 70000 SELECTS on an IPK..................................... 1.110s
- 500 - 70000 REPLACE on TEXT PK.................................... 1.812s
- 510 - 70000 SELECTS on a TEXT PK.................................. 1.760s
- 520 - 70000 SELECT DISTINCT....................................... 1.026s
- 980 - PRAGMA integrity_check...................................... 4.948s
- 990 - ANALYZE..................................................... 0.576s
- TOTAL....................................................... 68.801s
-
复制代码
PC端对比下 编译 gcc sqlite3.c speedtest1.c -o speedtest1pc -lpthread -ldl 挂载在/mnt/d执行
- lhj@lhj:/mnt/d/BOARD/万象奥科HD-G2UL-EVM/proj/sqlite-amalgamation-3400000$ ./speedtest1pc
- -- Speedtest1 for SQLite 3.40.0 2022-11-16 12:10:08 89c459e766ea7e9165d0beeb1247
- 100 - 50000 INSERTs into table with no index...................... 0.058s
- 110 - 50000 ordered INSERTS with one index/PK..................... 0.074s
- 120 - 50000 unordered INSERTS with one index/PK................... 0.092s
- 130 - 25 SELECTS, numeric BETWEEN, unindexed...................... 0.082s
- 140 - 10 SELECTS, LIKE, unindexed................................. 0.105s
- 142 - 10 SELECTS w/ORDER BY, unindexed............................ 0.147s
- 145 - 10 SELECTS w/ORDER BY and LIMIT, unindexed.................. 0.089s
- 150 - CREATE INDEX five times..................................... 0.111s
- 160 - 10000 SELECTS, numeric BETWEEN, indexed..................... 0.085s
- 161 - 10000 SELECTS, numeric BETWEEN, PK.......................... 0.089s
- 170 - 10000 SELECTS, text BETWEEN, indexed........................ 0.210s
- 180 - 50000 INSERTS with three indexes............................ 0.160s
- 190 - DELETE and REFILL one table................................. 0.162s
- 200 - VACUUM...................................................... 0.141s
- 210 - ALTER TABLE ADD COLUMN, and query........................... 0.004s
- 230 - 10000 UPDATES, numeric BETWEEN, indexed..................... 0.090s
- 240 - 50000 UPDATES of individual rows............................ 0.147s
- 250 - One big UPDATE of the whole 50000-row table................. 0.016s
- 260 - Query added column after filling............................ 0.005s
- 270 - 10000 DELETEs, numeric BETWEEN, indexed..................... 0.254s
- 280 - 50000 DELETEs of individual rows............................ 0.186s
- 290 - Refill two 50000-row tables using REPLACE................... 0.342s
- 300 - Refill a 50000-row table using (b&1)==(a&1)................. 0.144s
- 310 - 10000 four-ways joins....................................... 0.439s
- 320 - subquery in result set...................................... 0.368s
- 400 - 70000 REPLACE ops on an IPK................................. 0.092s
- 410 - 70000 SELECTS on an IPK..................................... 0.062s
- 500 - 70000 REPLACE on TEXT PK.................................... 0.107s
- 510 - 70000 SELECTS on a TEXT PK.................................. 0.102s
- 520 - 70000 SELECT DISTINCT....................................... 0.065s
- 980 - PRAGMA integrity_check...................................... 0.317s
- 990 - ANALYZE..................................................... 0.034s
- TOTAL....................................................... 4.379s
复制代码
直接在wsl的~执行,快一点
- lhj@lhj:~$ ./speedtest1pc
- -- Speedtest1 for SQLite 3.40.0 2022-11-16 12:10:08 89c459e766ea7e9165d0beeb1247
- 100 - 50000 INSERTs into table with no index...................... 0.050s
- 110 - 50000 ordered INSERTS with one index/PK..................... 0.074s
- 120 - 50000 unordered INSERTS with one index/PK................... 0.096s
- 130 - 25 SELECTS, numeric BETWEEN, unindexed...................... 0.088s
- 140 - 10 SELECTS, LIKE, unindexed................................. 0.110s
- 142 - 10 SELECTS w/ORDER BY, unindexed............................ 0.152s
- 145 - 10 SELECTS w/ORDER BY and LIMIT, unindexed.................. 0.085s
- 150 - CREATE INDEX five times..................................... 0.113s
- 160 - 10000 SELECTS, numeric BETWEEN, indexed..................... 0.087s
- 161 - 10000 SELECTS, numeric BETWEEN, PK.......................... 0.092s
- 170 - 10000 SELECTS, text BETWEEN, indexed........................ 0.206s
- 180 - 50000 INSERTS with three indexes............................ 0.155s
- 190 - DELETE and REFILL one table................................. 0.155s
- 200 - VACUUM...................................................... 0.127s
- 210 - ALTER TABLE ADD COLUMN, and query........................... 0.006s
- 230 - 10000 UPDATES, numeric BETWEEN, indexed..................... 0.088s
- 240 - 50000 UPDATES of individual rows............................ 0.145s
- 250 - One big UPDATE of the whole 50000-row table................. 0.015s
- 260 - Query added column after filling............................ 0.004s
- 270 - 10000 DELETEs, numeric BETWEEN, indexed..................... 0.259s
- 280 - 50000 DELETEs of individual rows............................ 0.181s
- 290 - Refill two 50000-row tables using REPLACE................... 0.351s
- 300 - Refill a 50000-row table using (b&1)==(a&1)................. 0.151s
- 310 - 10000 four-ways joins....................................... 0.436s
- 320 - subquery in result set...................................... 0.356s
- 400 - 70000 REPLACE ops on an IPK................................. 0.085s
- 410 - 70000 SELECTS on an IPK..................................... 0.058s
- 500 - 70000 REPLACE on TEXT PK.................................... 0.109s
- 510 - 70000 SELECTS on a TEXT PK.................................. 0.102s
- 520 - 70000 SELECT DISTINCT....................................... 0.064s
- 980 - PRAGMA integrity_check...................................... 0.334s
- 990 - ANALYZE..................................................... 0.033s
- TOTAL....................................................... 4.367s
- lhj@lhj:~$
复制代码
总结 以上可以看出数据库的执行速度综合反应了IO的性能,比如文件系统的性能,例如WSL中直接执行比挂载在/mnt/d下快一点。也综合反映了CPU性能。 开发板与我的电脑:12th Gen Intel(R) Core(TM) i5-12500H 2.50 GHz,16GRAM,固态硬盘这样的配置对比,大概是差距16倍。这对于嵌入式开发板来说性能已经很好了。如果有其他开发板可以横向对比测试下。
|