ProgrammingModerate
A program runs a loop body 10^8 times and each iteration does one multiply and one add on ints. Roughly how long does this take on typical hardware?
- A. Several hours
- B. Well under a second, often around a tenth of a second
- C. About 10 minutes
- D. Roughly a year
Correct answer: B. Well under a second, often around a tenth of a second
A simple loop does about 10^9 simple operations per second, so 10^8 iterations take around a tenth of a second.
More C Programming questions
- A bit-packed bitset of 10^9 bits needs how much memory?
- Which loop is correct and fast enough to find the largest element of an array of 10^7 ints, reading each value once?
- A program must answer 10^6 queries 'is x present in the set S?' where S has 10^6 values fixed in advance. Which preprocessing and query…
- How many times does a body run in for (int i = 2; i < 100; i = i)?
- Which change makes the loop for (int i = 0; i < strlen(s); i++) run in linear time?
- A 2D grid of 2000 x 2000 cells is searched by a BFS that visits each cell once. About how many cell visits happen?