linux – SQLite查询的执行时间:单位

前端之家收集整理的这篇文章主要介绍了linux – SQLite查询的执行时间:单位前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
SQLite Documentation所述,人们可以使用:
  1. sqlite> .timer ON

或者向〜/ .sqliterc添加相同的命令

当这样做完成时,sqlite shell会响应执行的每个查询cpu Time的用户和sys组件:

  1. user@machine% sqlite3 test.db
  2. -- Loading resources from ~/.sqliterc
  3.  
  4. sqlite version 3.7.14 2012-09-03 15:42:36
  5. Enter ".help" for instructions
  6. Enter sql statements terminated with a ";"
  7.  
  8. sqlite> select count(*) from my_table;
  9. count(*)
  10. 10143270
  11. cpu Time: user 0.199970 sys 1.060838

当我发现this answer为几秒钟的时间单位提供证据时,我很难同意.当使用秒表计时执行查询时,我发现几乎每个查询的花费要比使用shell的时间长.例如,上述示例中的查询大概花了1分54秒的时间.这个差异的原因是什么?

那么再一次,单位是什么?什么是用户和系统组件?

我在运行sqlite 3.7.14的Debian GNU / Linux 6.0.6(挤压)分发可通过NFS访问.

解决方法

用户cpu花费在用户空间中执行代码(即数据库本身)的时间; sys是用于内核中的代码.

在执行I / O时,cpu大部分时间都在等待.

sqlite的最新版本也显示经过实时的时间:

  1. sqlite version 3.8.6 2014-08-15 11:46:33
  2. Enter ".help" for usage hints.
  3. Connected to a transient in-memory database.
  4. Use ".open FILENAME" to reopen on a persistent database.
  5. sqlite> .timer on
  6. sqlite> UPDATE ...;
  7. Run Time: real 36.591 user 17.362911 sys 1.809612

猜你在找的Linux相关文章