We need a few more components:
Registers give us SRAM which can hold a value as long as the system has power
another way to physically store a value¶
DRAM uses one transistor and one capacitor. (SRAM uses 4-6 transistors)
a capacitor holds a charge for a time, but gradually fades, so it has to be refreshed
ROM is a diode matrix traditionally
hardward encodes the instructions
cannot be changed without rewiring
PROM¶
can be reprogrammed once after device is made
used for firmware/microcode
(programmable ROM)
EPROM or EEPROM¶
treated like ROM
can be erased & reprogrammed
but not infinitely, very limited number of tmes
holds value when power goes away, UV light or electriciy can re-program
SRAM:¶
is volatile; it needs power to hold a value
is fast
takes up more space on the chip (uses 4-6 transistors per bit)
typically used of cache and internal registers
DRAM:¶
is volatile; it needs power to hold a value
is slower and requires a refresh
is small (1 transistor + 1 capacitor per bit) and space efficient
used for the main RAM
Flash memory¶
non-volatile; holds a value without power, can be electircally erased and re-programmed
comprised of memory “cells” in layerd boards
memory cells are mosfets - a different type of transistor that retains a state after power is removed and put bag
implemented with EEPROM
designed for large blocks and limited writes (~10k)
used for ssd, usb flash drives, smartphones, etc
slow to write, fast to read
Why does this matter?¶
Solution to Exercise 2 #
import timeit
from numpy import round
one_line = '5+7+9'
multi_line = """\
a = 5
b = 7
c = 9
a+b+c
"""
one_line_time = timeit.timeit(one_line,number=10000)
multi_line_time = timeit.timeit(multi_line,number=10000)
one_line_time, multi_line_time(0.00012128599999527978, 0.0004468760000122529)From this, we see that 0.00012128599999527978 is smaller than 0.0004468760000122529; in fact it is 3.68x faster to do the addition in 1 line without variables.
We can even see that it takes more time to store the value to a variable than to only compute it:
one_line_store = 's=5+7+9'
one_line_store_time = timeit.timeit(one_line_store,number=10000)
one_line_store_time0.000161362000000053740.00016136200000005374 is just a little bit more than 0.00012128599999527978, but it is still more.
This is not to say that it is not good to create variables; readability of code also matters, but it is important to know what can speed things up. Speeding things up can reduce electricity use of code and save money, but it can also cost more time if no one else can understand your code. It’s a tradeoff that you have to make as a developer.
Solution to Exercise 3
Since reading ssd is fast, but writing is slow, the first one would be faster, as long as there was no parallelization and the processing was relatively fast.
If you can process the chunks in parallel in the second case it could be faster if the processing was complex enough that it overtakes the time to write
Prepare for Next Class¶
since this is posted late, you will get time for the following at the start of class
read the notes from 11/13 there is a more detailed solution to the problems we did in class
Trace through the ripple carry adder to see how different calculations take different amounts of time. Find up with 2 example addition problems that demonstrate how much the time can vary(one short, one long).
hint use electron mode instead of immediate and it will count. There is also a “reload” button that will reset the counter.
Badges¶
Review the notes from today
compare and contrast two different types of storage (choose two: register, RAM, ROM, disk) using an analogy of your choice. You may use AI to help, but you need to be able to discuss the idea. To get credit for this badge, you must discuss with Dr. Brown either in lab or office hours.
Review the notes from today
compare and contrast the four different types of storage (register, RAM, ROM, disk) using an analogy of your choice. You may use AI to help, but you need to be able to discuss the idea. To get credit for this badge, you must discuss with Dr. Brown either in lab or office hours.