<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
algorithmic	B-General_Concept
efficiency	I-General_Concept
is	O
a	O
property	O
of	O
an	O
algorithm	O
which	O
relates	O
to	O
the	O
amount	O
of	O
computational	O
resources	O
used	O
by	O
the	O
algorithm	O
.	O
</s>
<s>
An	O
algorithm	O
must	O
be	O
analyzed	B-General_Concept
to	O
determine	O
its	O
resource	O
usage	O
,	O
and	O
the	O
efficiency	O
of	O
an	O
algorithm	O
can	O
be	O
measured	O
based	O
on	O
the	O
usage	O
of	O
different	O
resources	O
.	O
</s>
<s>
Algorithmic	B-General_Concept
efficiency	I-General_Concept
can	O
be	O
thought	O
of	O
as	O
analogous	O
to	O
engineering	O
productivity	O
for	O
a	O
repeating	O
or	O
continuous	O
process	O
.	O
</s>
<s>
For	O
example	O
,	O
bubble	B-Algorithm
sort	I-Algorithm
and	O
timsort	B-Algorithm
are	O
both	O
algorithms	B-Algorithm
to	I-Algorithm
sort	I-Algorithm
a	I-Algorithm
list	I-Algorithm
of	O
items	O
from	O
smallest	O
to	O
largest	O
.	O
</s>
<s>
Bubble	B-Algorithm
sort	I-Algorithm
sorts	O
the	O
list	O
in	O
time	O
proportional	O
to	O
the	O
number	O
of	O
elements	O
squared	O
(	O
,	O
see	O
Big	O
O	O
notation	O
)	O
,	O
but	O
only	O
requires	O
a	O
small	O
amount	O
of	O
extra	O
memory	B-General_Concept
which	O
is	O
constant	O
with	O
respect	O
to	O
the	O
length	O
of	O
the	O
list	O
(	O
)	O
.	O
</s>
<s>
Timsort	B-Algorithm
sorts	O
the	O
list	O
in	O
time	O
linearithmic	O
(	O
proportional	O
to	O
a	O
quantity	O
times	O
its	O
logarithm	O
)	O
in	O
the	O
list	O
's	O
length	O
(	O
)	O
,	O
but	O
has	O
a	O
space	O
requirement	O
linear	O
in	O
the	O
length	O
of	O
the	O
list	O
(	O
)	O
.	O
</s>
<s>
If	O
large	O
lists	O
must	O
be	O
sorted	O
at	O
high	O
speed	O
for	O
a	O
given	O
application	O
,	O
timsort	B-Algorithm
is	O
a	O
better	O
choice	O
;	O
however	O
,	O
if	O
minimizing	O
the	O
memory	B-General_Concept
footprint	O
of	O
the	O
sorting	B-Algorithm
is	O
more	O
important	O
,	O
bubble	B-Algorithm
sort	I-Algorithm
is	O
a	O
better	O
choice	O
.	O
</s>
<s>
The	O
importance	O
of	O
efficiency	O
with	O
respect	O
to	O
time	O
was	O
emphasised	O
by	O
Ada	B-General_Concept
Lovelace	I-General_Concept
in	O
1843	O
as	O
applied	O
to	O
Charles	O
Babbage	O
's	O
mechanical	O
analytical	O
engine	O
:	O
</s>
<s>
Early	O
electronic	O
computers	O
had	O
both	O
limited	O
speed	O
and	O
limited	O
random	B-Architecture
access	I-Architecture
memory	I-Architecture
.	O
</s>
<s>
A	O
task	B-General_Concept
could	O
use	O
a	O
fast	O
algorithm	O
using	O
a	O
lot	O
of	O
memory	B-General_Concept
,	O
or	O
it	O
could	O
use	O
a	O
slow	O
algorithm	O
using	O
little	O
memory	B-General_Concept
.	O
</s>
<s>
The	O
engineering	O
trade-off	O
was	O
then	O
to	O
use	O
the	O
fastest	O
algorithm	O
that	O
could	O
fit	O
in	O
the	O
available	O
memory	B-General_Concept
.	O
</s>
<s>
Modern	O
computers	O
are	O
significantly	O
faster	O
than	O
the	O
early	O
computers	O
,	O
and	O
have	O
a	O
much	O
larger	O
amount	O
of	O
memory	B-General_Concept
available	O
(	O
Gigabytes	B-Device
instead	I-Device
of	I-Device
Kilobytes	I-Device
)	O
.	O
</s>
<s>
Since	O
the	O
1950s	O
computers	O
have	O
seen	O
dramatic	O
increases	O
in	O
both	O
the	O
available	O
computational	O
power	O
and	O
in	O
the	O
available	O
amount	O
of	O
memory	B-General_Concept
,	O
so	O
current	O
acceptable	O
levels	O
would	O
have	O
been	O
unacceptable	O
even	O
10	O
years	O
ago	O
.	O
</s>
<s>
In	O
fact	O
,	O
thanks	O
to	O
the	O
approximate	O
doubling	O
of	O
computer	O
power	O
every	O
2	O
years	O
,	O
tasks	O
that	O
are	O
acceptably	O
efficient	O
on	O
modern	O
smartphones	B-Application
and	O
embedded	B-Architecture
systems	I-Architecture
may	O
have	O
been	O
unacceptably	O
inefficient	O
for	O
industrial	O
servers	O
10	O
years	O
ago	O
.	O
</s>
<s>
Software	O
costs	O
can	O
be	O
quite	O
high	O
,	O
so	O
in	O
some	O
cases	O
the	O
simplest	O
and	O
cheapest	O
way	O
of	O
getting	O
higher	O
performance	O
might	O
be	O
to	O
just	O
buy	O
a	O
faster	O
computer	O
,	O
provided	O
it	O
is	O
compatible	B-General_Concept
with	O
an	O
existing	O
computer	O
.	O
</s>
<s>
There	O
are	O
many	O
ways	O
in	O
which	O
the	O
resources	O
used	O
by	O
an	O
algorithm	O
can	O
be	O
measured	O
:	O
the	O
two	O
most	O
common	O
measures	O
are	O
speed	O
and	O
memory	B-General_Concept
usage	I-General_Concept
;	O
other	O
measures	O
could	O
include	O
transmission	O
speed	O
,	O
temporary	O
disk	O
usage	O
,	O
long-term	O
disk	O
usage	O
,	O
power	O
consumption	O
,	O
total	O
cost	O
of	O
ownership	O
,	O
response	O
time	O
to	O
external	O
stimuli	O
,	O
etc	O
.	O
</s>
<s>
They	O
might	O
also	O
depend	O
on	O
the	O
way	O
in	O
which	O
the	O
data	O
is	O
arranged	O
;	O
for	O
example	O
,	O
some	O
sorting	B-Algorithm
algorithms	I-Algorithm
perform	O
poorly	O
on	O
data	O
which	O
is	O
already	O
sorted	O
,	O
or	O
which	O
is	O
sorted	O
in	O
reverse	O
order	O
.	O
</s>
<s>
In	O
the	O
theoretical	O
analysis	B-General_Concept
of	I-General_Concept
algorithms	I-General_Concept
,	O
the	O
normal	O
practice	O
is	O
to	O
estimate	O
their	O
complexity	O
in	O
the	O
asymptotic	B-Language
sense	O
.	O
</s>
<s>
Big	O
O	O
notation	O
is	O
an	O
asymptotic	B-Language
measure	O
of	O
function	O
complexity	O
,	O
where	O
roughly	O
means	O
the	O
time	O
requirement	O
for	O
an	O
algorithm	O
is	O
proportional	O
to	O
,	O
omitting	O
lower-order	O
terms	O
that	O
contribute	O
less	O
than	O
to	O
the	O
growth	O
of	O
the	O
function	O
as	O
grows	B-Algorithm
arbitrarily	I-Algorithm
large	I-Algorithm
.	O
</s>
<s>
This	O
estimate	O
may	O
be	O
misleading	O
when	O
is	O
small	O
,	O
but	O
is	O
generally	O
sufficiently	O
accurate	O
when	O
is	O
large	O
as	O
the	O
notation	O
is	O
asymptotic	B-Language
.	O
</s>
<s>
For	O
example	O
,	O
bubble	B-Algorithm
sort	I-Algorithm
may	O
be	O
faster	O
than	O
merge	B-Algorithm
sort	I-Algorithm
when	O
only	O
a	O
few	O
items	O
are	O
to	O
be	O
sorted	O
;	O
however	O
either	O
implementation	O
is	O
likely	O
to	O
meet	O
performance	O
requirements	O
for	O
a	O
small	O
list	O
.	O
</s>
<s>
Typically	O
,	O
programmers	O
are	O
interested	O
in	O
algorithms	O
that	O
scale	B-Architecture
efficiently	O
to	O
large	O
input	O
sizes	O
,	O
and	O
merge	B-Algorithm
sort	I-Algorithm
is	O
preferred	O
over	O
bubble	B-Algorithm
sort	I-Algorithm
for	O
lists	O
of	O
length	O
encountered	O
in	O
most	O
data-intensive	O
programs	O
.	O
</s>
<s>
Some	O
examples	O
of	O
Big	O
O	O
notation	O
applied	O
to	O
algorithms	O
 '	O
asymptotic	B-Language
time	O
complexity	O
include	O
:	O
</s>
<s>
If	O
a	O
new	O
sort	B-Algorithm
algorithm	I-Algorithm
is	O
produced	O
,	O
for	O
example	O
,	O
it	O
can	O
be	O
compared	O
with	O
its	O
predecessors	O
to	O
ensure	O
that	O
at	O
least	O
it	O
is	O
efficient	O
as	O
before	O
with	O
known	O
data	O
,	O
taking	O
into	O
consideration	O
any	O
functional	O
improvements	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
mainframe	B-Architecture
world	O
certain	O
proprietary	O
sort	B-Application
products	O
from	O
independent	O
software	O
companies	O
such	O
as	O
Syncsort	O
compete	O
with	O
products	O
from	O
the	O
major	O
suppliers	O
such	O
as	O
IBM	O
for	O
speed	O
.	O
</s>
<s>
Implementation	O
issues	O
can	O
also	O
have	O
an	O
effect	O
on	O
efficiency	O
,	O
such	O
as	O
the	O
choice	O
of	O
programming	O
language	O
,	O
or	O
the	O
way	O
in	O
which	O
the	O
algorithm	O
is	O
actually	O
coded	O
,	O
or	O
the	O
choice	O
of	O
a	O
compiler	B-Language
for	O
a	O
particular	O
language	O
,	O
or	O
the	O
compilation	B-Application
options	I-Application
used	O
,	O
or	O
even	O
the	O
operating	B-General_Concept
system	I-General_Concept
being	O
used	O
.	O
</s>
<s>
In	O
many	O
cases	O
a	O
language	O
implemented	O
by	O
an	O
interpreter	B-Application
may	O
be	O
much	O
slower	O
than	O
a	O
language	O
implemented	O
by	O
a	O
compiler	B-Language
.	O
</s>
<s>
See	O
the	O
articles	O
on	O
just-in-time	O
compilation	B-Language
and	O
interpreted	B-Application
languages	I-Application
.	O
</s>
<s>
There	O
are	O
other	O
factors	O
which	O
may	O
affect	O
time	O
or	O
space	O
issues	O
,	O
but	O
which	O
may	O
be	O
outside	O
of	O
a	O
programmer	O
's	O
control	O
;	O
these	O
include	O
data	B-Application
alignment	I-Application
,	O
data	O
granularity	O
,	O
cache	B-General_Concept
locality	I-General_Concept
,	O
cache	B-General_Concept
coherency	I-General_Concept
,	O
garbage	B-General_Concept
collection	I-General_Concept
,	O
instruction-level	B-Operating_System
parallelism	I-Operating_System
,	O
multi-threading	O
(	O
at	O
either	O
a	O
hardware	O
or	O
software	O
level	O
)	O
,	O
simultaneous	B-Operating_System
multitasking	I-Operating_System
,	O
and	O
subroutine	O
calls	O
.	O
</s>
<s>
Some	O
processors	O
have	O
capabilities	O
for	O
vector	B-Operating_System
processing	I-Operating_System
,	O
which	O
allow	O
a	O
single	B-Device
instruction	I-Device
to	I-Device
operate	I-Device
on	I-Device
multiple	I-Device
operands	I-Device
;	O
it	O
may	O
or	O
may	O
not	O
be	O
easy	O
for	O
a	O
programmer	O
or	O
compiler	B-Language
to	O
use	O
these	O
capabilities	O
.	O
</s>
<s>
Algorithms	O
designed	O
for	O
sequential	O
processing	O
may	O
need	O
to	O
be	O
completely	O
redesigned	O
to	O
make	O
use	O
of	O
parallel	B-Operating_System
processing	I-Operating_System
,	O
or	O
they	O
could	O
be	O
easily	O
reconfigured	O
.	O
</s>
<s>
As	O
parallel	B-Operating_System
and	O
distributed	B-Architecture
computing	I-Architecture
grow	O
in	O
importance	O
in	O
the	O
late	O
2010s	O
,	O
more	O
investments	O
are	O
being	O
made	O
into	O
efficient	O
high-level	B-Language
APIs	B-Application
for	O
parallel	B-Operating_System
and	O
distributed	B-Architecture
computing	I-Architecture
systems	O
such	O
as	O
CUDA	B-Architecture
,	O
TensorFlow	B-Language
,	O
Hadoop	B-Application
,	O
OpenMP	B-Application
and	O
MPI	B-Application
.	O
</s>
<s>
Another	O
problem	O
which	O
can	O
arise	O
in	O
programming	O
is	O
that	O
processors	O
compatible	B-General_Concept
with	O
the	O
same	O
instruction	B-General_Concept
set	I-General_Concept
(	O
such	O
as	O
x86-64	B-Device
or	O
ARM	B-Architecture
)	O
may	O
implement	O
an	O
instruction	O
in	O
different	O
ways	O
,	O
so	O
that	O
instructions	O
which	O
are	O
relatively	O
fast	O
on	O
some	O
models	O
may	O
be	O
relatively	O
slow	O
on	O
other	O
models	O
.	O
</s>
<s>
This	O
often	O
presents	O
challenges	O
to	O
optimizing	B-Application
compilers	I-Application
,	O
which	O
must	O
have	O
a	O
great	O
amount	O
of	O
knowledge	O
of	O
the	O
specific	O
CPU	B-General_Concept
and	O
other	O
hardware	O
available	O
on	O
the	O
compilation	B-Language
target	O
to	O
best	O
optimize	O
a	O
program	O
for	O
performance	O
.	O
</s>
<s>
In	O
the	O
extreme	O
case	O
,	O
a	O
compiler	B-Language
may	O
be	O
forced	O
to	O
emulate	B-Application
instructions	O
not	O
supported	O
on	O
a	O
compilation	B-Language
target	O
platform	O
,	O
forcing	O
it	O
to	O
generate	B-Application
code	I-Application
or	O
link	B-Application
an	O
external	O
library	B-Library
call	I-Library
to	O
produce	O
a	O
result	O
that	O
is	O
otherwise	O
incomputable	O
on	O
that	O
platform	O
,	O
even	O
if	O
it	O
is	O
natively	O
supported	O
and	O
more	O
efficient	O
in	O
hardware	O
on	O
other	O
platforms	O
.	O
</s>
<s>
This	O
is	O
often	O
the	O
case	O
in	O
embedded	B-Architecture
systems	I-Architecture
with	O
respect	O
to	O
floating-point	B-Algorithm
arithmetic	I-Algorithm
,	O
where	O
small	O
and	O
low-power	O
microcontrollers	B-Architecture
often	O
lack	O
hardware	O
support	O
for	O
floating-point	B-Algorithm
arithmetic	I-Algorithm
and	O
thus	O
require	O
computationally	B-General_Concept
expensive	I-General_Concept
software	O
routines	O
to	O
produce	O
floating	B-Algorithm
point	I-Algorithm
calculations	O
.	O
</s>
<s>
Space	O
:	O
how	O
much	O
working	O
memory	B-General_Concept
(	O
typically	O
RAM	B-Architecture
)	O
is	O
needed	O
by	O
the	O
algorithm	O
?	O
</s>
<s>
This	O
has	O
two	O
aspects	O
:	O
the	O
amount	O
of	O
memory	B-General_Concept
needed	O
by	O
the	O
code	O
(	O
auxiliary	O
space	O
usage	O
)	O
,	O
and	O
the	O
amount	O
of	O
memory	B-General_Concept
needed	O
for	O
the	O
data	O
on	O
which	O
the	O
code	O
operates	O
(	O
intrinsic	O
space	O
usage	O
)	O
.	O
</s>
<s>
laptops	B-Device
and	O
smartphones	B-Application
)	O
,	O
or	O
for	O
very	O
long/large	O
calculations	O
(	O
e.g.	O
</s>
<s>
supercomputers	B-Architecture
)	O
,	O
other	O
measures	O
of	O
interest	O
are	O
:	O
</s>
<s>
,	O
power	O
consumption	O
is	O
growing	O
as	O
an	O
important	O
metric	O
for	O
computational	O
tasks	O
of	O
all	O
types	O
and	O
at	O
all	O
scales	O
ranging	O
from	O
embedded	B-Architecture
Internet	B-Operating_System
of	I-Operating_System
things	I-Operating_System
devices	O
to	O
system-on-chip	B-Architecture
devices	O
to	O
server	B-Operating_System
farms	I-Operating_System
.	O
</s>
<s>
Data	B-General_Concept
compression	I-General_Concept
can	O
be	O
used	O
to	O
reduce	O
the	O
amount	O
of	O
data	O
to	O
be	O
transmitted	O
.	O
</s>
<s>
This	O
is	O
important	O
for	O
I/O	B-General_Concept
bound	I-General_Concept
computing	I-General_Concept
tasks	O
.	O
</s>
<s>
External	O
space	O
:	O
space	O
needed	O
on	O
a	O
disk	O
or	O
other	O
external	O
memory	B-General_Concept
device	I-General_Concept
;	O
this	O
could	O
be	O
for	O
temporary	O
storage	O
while	O
the	O
algorithm	O
is	O
being	O
carried	O
out	O
,	O
or	O
it	O
could	O
be	O
long-term	O
storage	O
needed	O
to	O
be	O
carried	O
forward	O
for	O
future	O
reference	O
.	O
</s>
<s>
Response	O
time	O
(	O
latency	O
)	O
:	O
this	O
is	O
particularly	O
relevant	O
in	O
a	O
real-time	B-General_Concept
application	I-General_Concept
when	O
the	O
computer	O
system	O
must	O
respond	B-Application
quickly	I-Application
to	I-Application
some	I-Application
external	I-Application
event	I-Application
.	O
</s>
<s>
Analyze	B-General_Concept
the	O
algorithm	O
,	O
typically	O
using	O
time	O
complexity	B-General_Concept
analysis	I-General_Concept
to	O
get	O
an	O
estimate	O
of	O
the	O
running	O
time	O
as	O
a	O
function	O
of	O
the	O
size	O
of	O
the	O
input	B-General_Concept
data	I-General_Concept
.	O
</s>
<s>
Algorithms	B-Operating_System
which	I-Operating_System
include	I-Operating_System
parallel	I-Operating_System
processing	I-Operating_System
may	O
be	O
more	B-Operating_System
difficult	I-Operating_System
to	I-Operating_System
analyze	I-Operating_System
.	O
</s>
<s>
Many	O
programming	O
languages	O
have	O
an	O
available	O
function	O
which	O
provides	O
CPU	B-General_Concept
time	O
usage	O
.	O
</s>
<s>
Run-based	O
profiling	O
can	O
be	O
very	O
sensitive	O
to	O
hardware	O
configuration	O
and	O
the	O
possibility	O
of	O
other	O
programs	O
or	O
tasks	O
running	O
at	O
the	O
same	O
time	O
in	O
a	O
multi-processing	B-Operating_System
and	O
multi-programming	B-Operating_System
environment	O
.	O
</s>
<s>
This	O
sort	B-Application
of	O
test	O
also	O
depends	O
heavily	O
on	O
the	O
selection	O
of	O
a	O
particular	O
programming	O
language	O
,	O
compiler	B-Language
,	O
and	O
compiler	B-Language
options	O
,	O
so	O
algorithms	O
being	O
compared	O
must	O
all	O
be	O
implemented	O
under	O
the	O
same	O
conditions	O
.	O
</s>
<s>
This	O
section	O
is	O
concerned	O
with	O
use	O
of	O
memory	B-General_Concept
resources	O
(	O
registers	B-General_Concept
,	O
cache	B-General_Concept
,	O
RAM	B-Architecture
,	O
virtual	B-Architecture
memory	I-Architecture
,	O
secondary	O
memory	B-General_Concept
)	O
while	O
the	O
algorithm	O
is	O
being	O
executed	O
.	O
</s>
<s>
As	O
for	O
time	O
analysis	O
above	O
,	O
analyze	B-General_Concept
the	O
algorithm	O
,	O
typically	O
using	O
space	O
complexity	B-General_Concept
analysis	I-General_Concept
to	O
get	O
an	O
estimate	O
of	O
the	O
run-time	O
memory	B-General_Concept
needed	O
as	O
a	O
function	O
as	O
the	O
size	O
of	O
the	O
input	B-General_Concept
data	I-General_Concept
.	O
</s>
<s>
There	O
are	O
up	O
to	O
four	O
aspects	O
of	O
memory	B-General_Concept
usage	I-General_Concept
to	O
consider	O
:	O
</s>
<s>
The	O
amount	O
of	O
memory	B-General_Concept
needed	O
to	O
hold	O
the	O
code	O
for	O
the	O
algorithm	O
.	O
</s>
<s>
The	O
amount	O
of	O
memory	B-General_Concept
needed	O
for	O
the	O
input	B-General_Concept
data	I-General_Concept
.	O
</s>
<s>
The	O
amount	O
of	O
memory	B-General_Concept
needed	O
for	O
any	O
output	B-General_Concept
data	I-General_Concept
.	O
</s>
<s>
Some	O
algorithms	O
,	O
such	O
as	O
sorting	B-Algorithm
,	O
often	O
rearrange	B-Algorithm
the	I-Algorithm
input	I-Algorithm
data	I-Algorithm
and	O
do	O
not	O
need	O
any	O
additional	O
space	O
for	O
output	B-General_Concept
data	I-General_Concept
.	O
</s>
<s>
This	O
property	O
is	O
referred	O
to	O
as	O
"	O
in-place	B-Algorithm
"	O
operation	O
.	O
</s>
<s>
The	O
amount	O
of	O
memory	B-General_Concept
needed	O
as	O
working	O
space	O
during	O
the	O
calculation	O
.	O
</s>
<s>
Early	O
electronic	O
computers	O
,	O
and	O
early	O
home	O
computers	O
,	O
had	O
relatively	O
small	O
amounts	O
of	O
working	O
memory	B-General_Concept
.	O
</s>
<s>
For	O
example	O
,	O
the	O
1949	O
Electronic	B-Device
Delay	I-Device
Storage	I-Device
Automatic	I-Device
Calculator	I-Device
(	O
EDSAC	B-Device
)	O
had	O
a	O
maximum	O
working	O
memory	B-General_Concept
of	O
1024	O
17-bit	O
words	O
,	O
while	O
the	O
1980	O
Sinclair	B-Operating_System
ZX80	I-Operating_System
came	O
initially	O
with	O
1024	O
8-bit	O
bytes	O
of	O
working	O
memory	B-General_Concept
.	O
</s>
<s>
In	O
the	O
late	O
2010s	O
,	O
it	O
is	O
typical	O
for	O
personal	B-Device
computers	I-Device
to	O
have	O
between	O
4	O
and	O
32	O
GB	O
of	O
RAM	B-Architecture
,	O
an	O
increase	O
of	O
over	O
300	O
million	O
times	O
as	O
much	O
memory	B-General_Concept
.	O
</s>
<s>
Current	O
computers	O
can	O
have	O
relatively	O
large	O
amounts	O
of	O
memory	B-General_Concept
(	O
possibly	O
Gigabytes	O
)	O
,	O
so	O
having	O
to	O
squeeze	O
an	O
algorithm	O
into	O
a	O
confined	O
amount	O
of	O
memory	B-General_Concept
is	O
much	O
less	O
of	O
a	O
problem	O
than	O
it	O
used	O
to	O
be	O
.	O
</s>
<s>
But	O
the	O
presence	O
of	O
four	O
different	O
categories	O
of	O
memory	B-General_Concept
can	O
be	O
significant	O
:	O
</s>
<s>
Processor	B-General_Concept
registers	I-General_Concept
,	O
the	O
fastest	O
of	O
computer	B-General_Concept
memory	I-General_Concept
technologies	O
with	O
the	O
least	O
amount	O
of	O
storage	O
space	O
.	O
</s>
<s>
Most	O
direct	O
computation	O
on	O
modern	O
computers	O
occurs	O
with	O
source	O
and	O
destination	O
operands	O
in	O
registers	B-General_Concept
before	O
being	O
updated	O
to	O
the	O
cache	B-General_Concept
,	O
main	O
memory	B-General_Concept
and	O
virtual	B-Architecture
memory	I-Architecture
if	O
needed	O
.	O
</s>
<s>
On	O
a	O
processor	B-Architecture
core	I-Architecture
,	O
there	O
are	O
typically	O
on	O
the	O
order	O
of	O
hundreds	O
of	O
bytes	O
or	O
fewer	O
of	O
register	O
availability	O
,	O
although	O
a	O
register	B-General_Concept
file	I-General_Concept
may	O
contain	O
more	O
physical	O
registers	B-General_Concept
than	O
architectural	B-General_Concept
registers	B-General_Concept
defined	O
in	O
the	O
instruction	B-General_Concept
set	I-General_Concept
architecture	I-General_Concept
.	O
</s>
<s>
Cache	B-General_Concept
memory	I-General_Concept
is	O
the	O
second	O
fastest	O
and	O
second	O
smallest	O
memory	B-General_Concept
available	O
in	O
the	O
memory	B-General_Concept
hierarchy	I-General_Concept
.	O
</s>
<s>
Caches	B-General_Concept
are	O
present	O
in	O
CPUs	O
,	O
GPUs	O
,	O
hard	B-Device
disk	I-Device
drives	I-Device
and	O
external	O
peripherals	O
,	O
and	O
are	O
typically	O
implemented	O
in	O
static	B-Architecture
RAM	I-Architecture
.	O
</s>
<s>
Memory	B-General_Concept
caches	I-General_Concept
are	I-General_Concept
multi-leveled	I-General_Concept
;	O
lower	O
levels	O
are	O
larger	O
,	O
slower	O
and	O
typically	O
shared	B-General_Concept
between	O
processor	O
cores	O
in	O
multi-core	B-Architecture
processors	I-Architecture
.	O
</s>
<s>
In	O
order	O
to	O
process	O
operands	O
in	O
cache	B-General_Concept
memory	I-General_Concept
,	O
a	O
processing	O
unit	O
must	O
fetch	O
the	O
data	O
from	O
the	O
cache	B-General_Concept
,	O
perform	O
the	O
operation	O
in	O
registers	B-General_Concept
and	O
write	O
the	O
data	O
back	O
to	O
the	O
cache	B-General_Concept
.	O
</s>
<s>
This	O
operates	O
at	O
speeds	O
comparable	O
(	O
about	O
2-10	O
times	O
slower	O
)	O
with	O
the	O
CPU	B-General_Concept
or	O
GPU	O
's	O
arithmetic	B-General_Concept
logic	I-General_Concept
unit	I-General_Concept
or	O
floating-point	B-General_Concept
unit	I-General_Concept
if	O
in	O
the	O
L1	O
cache	B-General_Concept
.	O
</s>
<s>
It	O
is	O
about	O
10	O
times	O
slower	O
if	O
there	O
is	O
an	O
L1	O
cache	B-General_Concept
miss	O
and	O
it	O
must	O
be	O
retrieved	O
from	O
and	O
written	O
to	O
the	O
L2	O
cache	B-General_Concept
,	O
and	O
a	O
further	O
10	O
times	O
slower	O
if	O
there	O
is	O
an	O
L2	O
cache	B-General_Concept
miss	O
and	O
it	O
must	O
be	O
retrieved	O
from	O
an	O
L3	O
cache	B-General_Concept
,	O
if	O
present	O
.	O
</s>
<s>
Main	O
physical	O
memory	B-General_Concept
is	O
most	O
often	O
implemented	O
in	O
dynamic	O
RAM	B-Architecture
(	O
DRAM	O
)	O
.	O
</s>
<s>
The	O
main	O
memory	B-General_Concept
is	O
much	O
larger	O
(	O
typically	O
gigabytes	O
compared	O
to	O
≈8	O
megabytes	O
)	O
than	O
an	O
L3	O
CPU	B-General_Concept
cache	I-General_Concept
,	O
with	O
read	O
and	O
write	O
latencies	O
typically	O
10-100	O
times	O
slower	O
.	O
</s>
<s>
,	O
RAM	B-Architecture
is	O
increasingly	O
implemented	O
on-chip	B-Architecture
of	O
processors	O
,	O
as	O
CPU	B-General_Concept
or	O
GPU	O
memory	B-General_Concept
.	O
</s>
<s>
Virtual	B-Architecture
memory	I-Architecture
is	O
most	O
often	O
implemented	O
in	O
terms	O
of	O
secondary	O
storage	O
such	O
as	O
a	O
hard	B-Device
disk	I-Device
,	O
and	O
is	O
an	O
extension	O
to	O
the	O
memory	B-General_Concept
hierarchy	I-General_Concept
that	O
has	O
much	O
larger	O
storage	O
space	O
but	O
much	O
larger	O
latency	O
,	O
typically	O
around	O
1000	O
times	O
slower	O
than	O
a	O
cache	B-General_Concept
miss	O
for	O
a	O
value	O
in	O
RAM	B-Architecture
.	O
</s>
<s>
While	O
originally	O
motivated	O
to	O
create	O
the	O
impression	O
of	O
higher	O
amounts	O
of	O
memory	B-General_Concept
being	O
available	O
than	O
were	O
truly	O
available	O
,	O
virtual	B-Architecture
memory	I-Architecture
is	O
more	O
important	O
in	O
contemporary	O
usage	O
for	O
its	O
time-space	O
tradeoff	O
and	O
enabling	O
the	O
usage	O
of	O
virtual	B-Architecture
machines	I-Architecture
.	O
</s>
<s>
Cache	B-General_Concept
misses	O
from	O
main	O
memory	B-General_Concept
are	O
called	O
page	B-General_Concept
faults	I-General_Concept
,	O
and	O
incur	O
huge	O
performance	O
penalties	O
on	O
programs	O
.	O
</s>
<s>
An	O
algorithm	O
whose	O
memory	B-General_Concept
needs	O
will	O
fit	O
in	O
cache	B-General_Concept
memory	I-General_Concept
will	O
be	O
much	O
faster	O
than	O
an	O
algorithm	O
which	O
fits	O
in	O
main	O
memory	B-General_Concept
,	O
which	O
in	O
turn	O
will	O
be	O
very	O
much	O
faster	O
than	O
an	O
algorithm	O
which	O
has	O
to	O
resort	O
to	O
virtual	B-Architecture
memory	I-Architecture
.	O
</s>
<s>
Because	O
of	O
this	O
,	O
cache	B-General_Concept
replacement	I-General_Concept
policies	I-General_Concept
are	O
extremely	O
important	O
to	O
high-performance	B-Architecture
computing	I-Architecture
,	O
as	O
are	O
cache-aware	O
programming	O
and	O
data	B-Application
alignment	I-Application
.	O
</s>
<s>
To	O
further	O
complicate	O
the	O
issue	O
,	O
some	O
systems	O
have	O
up	O
to	O
three	O
levels	O
of	O
cache	B-General_Concept
memory	I-General_Concept
,	O
with	O
varying	O
effective	O
speeds	O
.	O
</s>
<s>
Different	O
systems	O
will	O
have	O
different	O
amounts	O
of	O
these	O
various	O
types	O
of	O
memory	B-General_Concept
,	O
so	O
the	O
effect	O
of	O
algorithm	O
memory	B-General_Concept
needs	O
can	O
vary	O
greatly	O
from	O
one	O
system	O
to	O
another	O
.	O
</s>
<s>
In	O
the	O
early	O
days	O
of	O
electronic	O
computing	O
,	O
if	O
an	O
algorithm	O
and	O
its	O
data	O
would	O
not	O
fit	O
in	O
main	O
memory	B-General_Concept
then	O
the	O
algorithm	O
could	O
not	O
be	O
used	O
.	O
</s>
<s>
Nowadays	O
the	O
use	O
of	O
virtual	B-Architecture
memory	I-Architecture
appears	O
to	O
provide	O
much	O
memory	B-General_Concept
,	O
but	O
at	O
the	O
cost	O
of	O
performance	O
.	O
</s>
<s>
If	O
an	O
algorithm	O
and	O
its	O
data	O
will	O
fit	O
in	O
cache	B-General_Concept
memory	I-General_Concept
,	O
then	O
very	O
high	O
speed	O
can	O
be	O
obtained	O
;	O
in	O
this	O
case	O
minimizing	O
space	O
will	O
also	O
help	O
minimize	O
time	O
.	O
</s>
<s>
This	O
is	O
called	O
the	O
principle	O
of	O
locality	O
,	O
and	O
can	O
be	O
subdivided	O
into	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
,	O
spatial	O
locality	O
and	O
temporal	B-General_Concept
locality	I-General_Concept
.	O
</s>
<s>
An	O
algorithm	O
which	O
will	O
not	O
fit	O
completely	O
in	O
cache	B-General_Concept
memory	I-General_Concept
but	O
which	O
exhibits	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
may	O
perform	O
reasonably	O
well	O
.	O
</s>
<s>
David	O
May	O
FRS	O
a	O
British	O
computer	O
scientist	O
and	O
currently	O
Professor	O
of	O
Computer	B-General_Concept
Science	I-General_Concept
at	O
University	O
of	O
Bristol	O
and	O
founder	O
and	O
CTO	O
of	O
XMOS	O
Semiconductor	O
,	O
believes	O
one	O
of	O
the	O
problems	O
is	O
that	O
there	O
is	O
a	O
reliance	O
on	O
Moore	O
's	O
law	O
to	O
solve	O
inefficiencies	O
.	O
</s>
<s>
He	O
estimates	O
there	O
has	O
been	O
a	O
70dB	O
factor	O
loss	O
of	O
productivity	O
or	O
"	O
99.99999	O
percent	O
,	O
of	O
its	O
ability	O
to	O
deliver	O
the	O
goods	O
"	O
,	O
since	O
the	O
1980s	O
—	O
"	O
When	O
Arthur	O
C	O
.	O
Clarke	O
compared	O
the	O
reality	O
of	O
computing	O
in	O
2001	O
to	O
the	O
computer	O
HAL	B-General_Concept
9000	I-General_Concept
in	O
his	O
book	O
2001	O
:	O
A	O
Space	O
Odyssey	O
,	O
he	O
pointed	O
out	O
how	O
wonderfully	O
small	O
and	O
powerful	O
computers	O
were	O
but	O
how	O
disappointing	O
computer	O
programming	O
had	O
become	O
"	O
.	O
</s>
