Know Your Limits

Greg Colvin

Man’s got to know his limitations.—Dirty Harry

YOUR RESOURCES ARE LiMiTED. You only have so much time and money to do your work, including the time and money needed to keep your knowledge, skills, and tools up to date. You can only work so hard, so fast, so smart, and so long. Your tools are only so powerful. Your target machines are only so power- ful. So you have to respect the limits of your resources.
How to respect those limits? Know yourself, know your people, know your budgets, and know your stuff. Especially, as a software engineer, know the space and time complexity of your data structures and algorithms, and the architecture and performance characteristics of your systems. Your job is to create an optimal marriage of software and systems.
Space and time complexity are given as the function O(f(n)), which for n equal the size of the input is the asymptotic space or time required as n grows to infinity. Important complexity classes
for f(n) include ln(n), n, n ln(n), ne, and
en. As graphing these functions clearly shows, as n gets bigger, O(ln(n)) is ever so much smaller than O(n) and O(n ln(n)), which are ever so much smaller than O(ne) and O(en). As Sean Parent puts it, for achievable n, all complexity classes amount to near-constant, near-linear, or near-infinite.
92 97 Things Every Programmer Should Know

Complexity analysis is measured in terms of an abstract machine, but software runs on real machines. Modern computer systems are orga- nized as hierarchies of physical and virtual machines, including language runtimes, operating systems, CPUs, cache memory, random-access mem- ory, disk drives, and networks. This table shows the limits on random access time and storage capacity for a typical networked server.
Register Cache line L1 cache L2 cache
RAM Disk LAN Internet
< 1 ns
1 ns
4 ns
20 ns 10 ms 20 ms 100 ms
64 b 64 B 64 KB 8 MB 32 GB 10 TB > 1 PB > 1 ZB
Access time
Capacity
Note that capacity and speed vary by several orders of magnitude. Caching and lookahead are used heavily at every level of our systems to hide this varia- tion, but they only work when access is predictable. When cache misses are frequent, the system will be thrashing. For example, to randomly inspect every byte on a hard drive could take 32 years. Even to randomly inspect every byte in RAM could take 11 minutes. Random access is not predictable. What is? That depends on the system, but reaccessing recently used items and accessing items sequentially are usually a win.
Algorithms and data structures vary in how effectively they use caches. For instance:
• Linear search makes good use of lookahead, but requires O(n) comparisons.
• Binary search of a sorted array requires only O(log(n)) comparisons.
• Search of a van Emde Boas tree is O(log(n)) and cache-oblivious.
How to choose? In the last analysis, by measuring. The table below shows the time required to search arrays of 64-bit integers via these three methods. On my computer:
• Linear search is competitive for small arrays, but loses exponen- tially for larger arrays.
• van Emde Boas wins hands down, thanks to its predictable access pattern.
8 40 64 70 512    100 4,096 160

You pays your money and you takes your choice.—Punch

Know Your Limits相关推荐

  1. R语言ggplot2可视化时间序列散点图、X轴和Y轴都是时间信息、使用as.POSIXct函数自定义指定Y轴的时间范围(setting time limits in y axis)

    R语言ggplot2可视化时间序列散点图.X轴和Y轴都是时间信息.使用as.POSIXct函数自定义指定Y轴的时间范围(setting time limits in y axis) 目录

  2. R语言ggplot2可视化并添加特定区间的回归线、R原生plot函数可视化并添加特定区间的回归线:Add Regression Line Between Certain Limits

    R语言ggplot2可视化并添加特定区间的回归线.R原生plot函数可视化并添加特定区间的回归线:Add Regression Line Between Certain Limits 目录

  3. C标准库 limits.h

    本文转载自:C 标准库 - <limits.h> 简介 limits.h 头文件决定了各种变量类型的各种属性.定义在该头文件中的宏限制了各种变量类型(比如 char.int 和 long) ...

  4. [转帖]linux文件描述符文件/etc/security/limits.conf

    linux文件描述符文件/etc/security/limits.conf https://blog.csdn.net/fanren224/article/details/79971359 需要多学习 ...

  5. 如何解决编译linux内核(解决声卡问题),遭遇fatal error: linux/limits.h: 没有那个文件或目录

    如何解决编译linux内核(解决声卡问题),遭遇fatal error: linux/limits.h: 没有那个文件或目录 参考文章: (1)如何解决编译linux内核(解决声卡问题),遭遇fata ...

  6. CentOS 6.x limits changed on a existing running process

    前段时间发了一篇关于CentOS 6.x ulimit配置文件变更为/etc/security/limits.d/90-nproc.conf  的文章. 但是如果你的系统中已经存在的进程的nproc是 ...

  7. C++ limits头文件

    具体用法参考C++官网 / /numeric_limits example #include <iostream> #include <limits> using namesp ...

  8. Centos 7 mysql Buffered warning: Changed limits: max_connections: 214 解决方法

    2019独角兽企业重金招聘Python工程师标准>>> Centos 7 mysql Buffered warning: Changed limits: max_connection ...

  9. boost的chrono模块explore limits探索极限的测试程序

    boost的chrono模块explore limits探索极限的测试程序 实现功能 C++实现代码 实现功能 boost的chrono模块explore limits探索极限的测试程序 C++实现代 ...

  10. Memory Limits for Windows and Windows Server Releases

    Memory Limits for Windows and Windows Server Releases 2018/05/31 9 分钟阅读时长 https://docs.microsoft.com ...

最新文章

  1. Java学习总结:54(集合输出)
  2. 1076 Forwards on Weibo
  3. HR收到Dota天梯2000分玩家的简历,给不给面试的机会呢?
  4. 深度剖析Kubernetes API Server三部曲 - part 1
  5. golang中的数字签名
  6. Windows 8 开发31日-第04日-新控件
  7. php服务模块在nginx中的安装失败,在已安装的nginx中添加模块
  8. 学会这些 Python 美图技巧,就等着女朋友夸你吧
  9. 01-BIO通讯模型
  10. CCPC-EDG专场——E.Buy and Delete
  11. Android中使用SurfaceView和Canvas来绘制动画
  12. Python歌词解析
  13. 结构专业规范大全_监理签字用语规范大全,就是这么专业!
  14. 2020牛客暑期多校训练营(第九场)K-The Flee Plan of Groundhog
  15. win11激活office出问题
  16. java pdf替换内容_Java添加、提取、替换和删除PDF图片
  17. 随机生成一个1 到100之间的整数,从键盘输入数字进行猜数,一共可以猜5次
  18. Linux内存管理 之 KSM功能介绍
  19. 【整理】常用电子设备功耗(不定期更新)
  20. editplus5激活码 (亲测可用)

热门文章

  1. ShareSDK for Android 版本:V 2.5.0发布
  2. TinkerCAD知识库:问题集锦
  3. LeanCloud从入门到放弃
  4. 史上最全的vue插件库
  5. speech contest
  6. 内网与外网有什么区别
  7. CH453D驱动点阵屏
  8. GGS节选:中欧有什么不同
  9. 高铁乘务员搜题软件哪个好?工资一般多少?
  10. plsql forall 详解