Overview
Reality in computer system
I- Computer arithmetic
- It does not generate random varibles
- It can not assume all uaual mathematucal properties
II- You've got to know assembly
You'll never write assembly but it is key to machine-level execution. Need to know how does the code flow from text to machine code
III- Memory matters
RAM(Random access memory) is an unphysical abstraction. Memory is not bounded, it must be allocated and managed. But many app are memory dominated. Memory performance is also uniform,meaning that types of memory can affect program's performance greatly. Memory referencing bug can be pernicious.
typedef struct{ int a[2]; double d; }struct_t; double fun(int i){ struct_t s; s.d=3.14; s.a[i]=12341234123511234; return s.d; }
The result gives
> input: 1 > > > output:3.14000 > > input:2 > > > output: 3.13999 > > input:3 > > > output:2.00006104 > > input:6 > > Segmentation fault
Memory bug is painfull!
Location allocated | Data | Stack | Location allocated |
---|---|---|---|
Crucial | 7 | fun | |
? | 6 | fun | |
? | 5 | fun | |
struct_t | d_high | 4 | fun |
struct_t | d_low | 3 | fun |
struct_t | a[1] | 2 | fun |
struct_t | a[0] | 1 | fun |
IV- There is more to performance than asymptotic complexity
- Constant factros matter too
- Exact op count can not predict performance! Optimize from different levels
void copyij(int scr[2048][2048],int dst [2048][2048]){ int i,j; for(i=0;i<2048;i++){ for(j=0;j<2048;j++){ //Swtich i and j in loop, performance change in 20 folds. dst[i][j]=src[i][j]; } } }
This case is due to the memory's organizations.
V- Computers do more that execute programs
- They need to get data in and out
- They communicate with each other