Logic and computer systems · GCSE · OCR J277 1.1.2, AQA 8525 3.4.5 · about 15 min
Clock speed, cores and cache, measured with models.
[1 mark]What does a clock speed of 3 GHz mean?
[1 mark]Why might doubling the cores not halve the time a program takes?
[1 mark]Why does more cache usually make a CPU faster?
[1 mark]A job takes 60 seconds on 1 core and all of it can be split. How many seconds on 4 cores?
[1 mark]What is a drawback of a higher clock speed?
Use run_cache(requests, size) on the request list [5, 6, 5, 7, 5, 6, 8, 5, 6, 7], for cache sizes 1 to 6. Print one line for each size in the form size <n>: <hits> hits, then print best size: <n> for the smallest cache that gets the most hits, working it out with a loop.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def run_cache(requests, size):
cache = []
hits = 0
for address in requests:
if address in cache:
hits = hits + 1
cache.remove(address)
elif len(cache) == size:
cache.pop(0)
cache.append(address)
return hits, len(requests) - hits
requests = [5, 6, 5, 7, 5, 6, 8, 5, 6, 7]The hint students can ask for: Call the model once for each size in the range, printing as you go. Track the best size by keeping it only when a size beats the best hits so far, so the smallest of equally good sizes wins.
from bugbot import *
connect()
def run_cache(requests, size):
cache = []
hits = 0
for address in requests:
if address in cache:
hits = hits + 1
cache.remove(address)
elif len(cache) == size:
cache.pop(0)
cache.append(address)
return hits, len(requests) - hits
requests = [5, 6, 5, 7, 5, 6, 8, 5, 6, 7]
best = 1
best_hits = -1
for size in range(1, 7):
hits, misses = run_cache(requests, size)
print(f"size {size}: {hits} hits")
if hits > best_hits:
best = size
best_hits = hits
print("best size:", best)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.