what does a profiler do
helps identify how long code takes to run
- functions that are called the most
- functions that run the longest
what are two reasons we may use way too much data
what can we do to optimize space?
what is compression
analyzing the data to find and remove redundant or useless info
describe two types of compression
lossless - does not lose any info (zip, flac)
lossy - loses some info (jpeg, mp3)
with compression, what are we sacrificing? what are we improving?
explain.
we are sacrificing time to improve how much space we use.
your program is taking too much space. what are your options to fix this problem and what should you try first?
what type of variables should be used with bit manipulation? why?
unsigned variables
what are the 3 steps to running a profiler
what are 4 key routes to optimize your code
when and why should you optimize your code? When shouldn’t you?
only optimize if there’s a big performance issue. otherwise, the code is likely “good enough”
optimizing often makes code harder to:
- maintain
- reuse
- understand
optimizing code often makes the code harder to: (3)
what is the 80-20 rule and what concept does it relate to?
relates to optimization
80% of the program’s execution is spent in 20% of the code
optimizing is about making our code do ______(more/less) work, not making the current work __________(faster/slower)
less
faster
explain and give examples of optimizing by pre-computation
examples:
- constants (like PI or a BUFFER)
- the length of a string or array
explain optimizing by data structures
linked list
- fast insertions
array
- fast searches
- good for sequential processing
optimization by caching trades ____ for _____
trades storage for speed
malloc allocates a number of
____________ memory locations
the compiler ________ the type on the bits
contiguous
- an array
overlays
void pointers are addresses that point at ________
memory
garbage collection is a form of ____________ memory management.
it attempts to reclaim _____________ which is…
automatic
garbage. memory occupied by objects that are no longer in use
what does the type of a pointer actually do?
tells us how to interpret the data we find at the place in memory it points to
what are three methods of garbage collection?
when should we collect garbage?
asap (proactive)
only when necessary (lazy)
- not enough space
somewhere in between
what is fragmentation? how do we solve this?
when space in a program is used inefficiently
- there’s spaces between memory
defragmentation is used to reorganize and store data in contiguous memory