0m0.0005s user 0m0.0004s sys 0m0.0000s The rows are: • Elapsed time of process • Seconds of user time devoted to process • Seconds of system time devoted to process 21
• Main Memory access is faster than disk • CPU Cache Memory (if exists) is faster than main memory • CPU Registers are fastest Binary Formats • Double precision arithmetic is slow • Floating point arithmetic is faster than double precision • Long integer arithmetic is faster than floating-point • Short Integer, fixed-point arithmetic is faster than long arithmetic • Bitwise arithmetic is fastest Arithmetic Operations • Exponentiation is slow • Division is faster than exponentiation • Multiplication is faster than division • Addition/Subtraction is faster than multiplication • Bitwise operations are fastest 24
i < n; i++) for( int j = 0; j < n * n; j++) sum++; Example 2 for(int i = 1; i < n; i = i * 2) sum++; Example 3 for(int i = 0; i < n; i++) for( int j = 0; j < n * n; j++) for(int k = 0; k < j; k++) sum++; 52
i < n; i++) for( int j = 0; j < n * n; j++) sum++; Correct answer: O(n^3) Example 2 for(int i = 1; i < n; i = i * 2) sum++; Example 3 for(int i = 0; i < n; i++) for( int j = 0; j < n * n; j++) for(int k = 0; k < j; k++) sum++; 53
i < n; i++) for( int j = 0; j < n * n; j++) sum++; Correct answer: O(n^3) Example 2 for(int i = 1; i < n; i = i * 2) sum++; Correct answer: O(log(N)) Example 3 for(int i = 0; i < n; i++) for( int j = 0; j < n * n; j++) for(int k = 0; k < j; k++) sum++; 54
i < n; i++) for( int j = 0; j < n * n; j++) sum++; Correct answer: O(n^3) Example 2 for(int i = 1; i < n; i = i * 2) sum++; Correct answer: O(log(N)) Example 3 for(int i = 0; i < n; i++) for( int j = 0; j < n * n; j++) for(int k = 0; k < j; k++) sum++; Correct answer: O(n^5) 55