Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

How to store a value

We need a few more components:

register

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

PROM

(programmable ROM)

EPROM or EEPROM

SRAM:

DRAM:

Flash memory

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_time
0.00016136200000005374

0.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

  1. read the notes from 11/13 there is a more detailed solution to the problems we did in class

  2. 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
Practice
  1. Review the notes from today

  2. 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.

Experience Report Evidence

Questions After Today’s Class