Compare commits
No commits in common. "87a8bbbf0f20b2af561381b657294fdb0217f643" and "c536e0b28b9a8721d4328affcd8f650469f0b438" have entirely different histories.
87a8bbbf0f
...
c536e0b28b
3 changed files with 7 additions and 65 deletions
|
|
@ -1,57 +0,0 @@
|
||||||
For simplicity, we only include the script for the improved algorithm. For the
|
|
||||||
intuitive algorithm, simply replace the algorithm. The imports timing and memory
|
|
||||||
usage tracking code are nearly identical.
|
|
||||||
|
|
||||||
\begin{lstlisting}[language=python]
|
|
||||||
#!/usr/bin/python3
|
|
||||||
import tracemalloc
|
|
||||||
from random import random
|
|
||||||
from math import floor, sqrt
|
|
||||||
#from statistics import mean, variance
|
|
||||||
from time import perf_counter
|
|
||||||
|
|
||||||
# starting the memory monitoring
|
|
||||||
tracemalloc.start()
|
|
||||||
|
|
||||||
start_time = perf_counter()
|
|
||||||
|
|
||||||
# store memory consumption before
|
|
||||||
current_before, peak_before = tracemalloc.get_traced_memory()
|
|
||||||
|
|
||||||
# algorithm (part to replace)
|
|
||||||
N = 10**6
|
|
||||||
Tot = 0
|
|
||||||
Tot2 = 0
|
|
||||||
for _ in range(N):
|
|
||||||
item = random()
|
|
||||||
Tot += item
|
|
||||||
Tot2 += item ** 2
|
|
||||||
mean = Tot / N
|
|
||||||
variance = Tot2 / (N-1) - mean**2
|
|
||||||
|
|
||||||
# store memory after
|
|
||||||
current_after, peak_after = tracemalloc.get_traced_memory()
|
|
||||||
|
|
||||||
end_time = perf_counter()
|
|
||||||
|
|
||||||
print("mean :", mean)
|
|
||||||
print("variance :", variance)
|
|
||||||
|
|
||||||
# displaying the memory usage
|
|
||||||
print("Used memory before : {} B (current), {} B (peak)".format(current_before,peak_before))
|
|
||||||
print("Used memory after : {} B (current), {} B (peak)".format(current_after,peak_after))
|
|
||||||
print("Used memory : {} B".format(peak_after - current_before))
|
|
||||||
print("Time : {} ms".format((end_time - start_time) * 1000))
|
|
||||||
|
|
||||||
tracemalloc.stop()
|
|
||||||
\end{lstlisting}
|
|
||||||
|
|
||||||
Example output:
|
|
||||||
\begin{lstlisting}[language=python]
|
|
||||||
mean : 0.5002592040785124
|
|
||||||
variance : 0.0833757719902084
|
|
||||||
Used memory before : 0 B (current), 0 B (peak)
|
|
||||||
Used memory after : 1308 B (current), 1336 B (peak)
|
|
||||||
Used memory : 1336 B
|
|
||||||
Time : 535.1873079998768 ms
|
|
||||||
\end{lstlisting}
|
|
||||||
|
|
@ -154,7 +154,7 @@ We set out to study the resource consumption of the algorithms. We implemented
|
||||||
the above formulae to calculate the mean and variance of $ N = 10^6 $ random
|
the above formulae to calculate the mean and variance of $ N = 10^6 $ random
|
||||||
numbers. We wrote the following algorithms \footnotemark :
|
numbers. We wrote the following algorithms \footnotemark :
|
||||||
|
|
||||||
\footnotetext{The full code used to measure performance can be found in Annex \ref{annex:performance}.}
|
\footnotetext{The full code used to measure performance can be found in Annex X.}
|
||||||
% TODO annex
|
% TODO annex
|
||||||
|
|
||||||
\paragraph{Intuitive algorithm} Store values first, calculate later
|
\paragraph{Intuitive algorithm} Store values first, calculate later
|
||||||
|
|
@ -166,9 +166,9 @@ mean = mean(values)
|
||||||
variance = variance(values)
|
variance = variance(values)
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
Execution time : $ 4.8 $ seconds
|
Execution time : $ ~ 4.8 $ seconds
|
||||||
|
|
||||||
Memory usage : $ 32 $ MB
|
Memory usage : $ ~ 32 $ MB
|
||||||
|
|
||||||
\paragraph{Improved algorithm} Continuous calculation
|
\paragraph{Improved algorithm} Continuous calculation
|
||||||
|
|
||||||
|
|
@ -184,9 +184,9 @@ mean = Tot / N
|
||||||
variance = Tot2 / (N-1) - mean**2
|
variance = Tot2 / (N-1) - mean**2
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
Execution time : $ 530 $ milliseconds
|
Execution time : $ ~ 530 $ milliseconds
|
||||||
|
|
||||||
Memory usage : $ 1.3 $ kB
|
Memory usage : $ ~ 1.3 $ kB
|
||||||
|
|
||||||
\paragraph{Analysis} Memory usage is, as expected, much lower when calculating
|
\paragraph{Analysis} Memory usage is, as expected, much lower when calculating
|
||||||
the statistics on the fly. Furthermore, something we hadn't anticipated is the
|
the statistics on the fly. Furthermore, something we hadn't anticipated is the
|
||||||
|
|
|
||||||
|
|
@ -106,10 +106,9 @@
|
||||||
\clearpage
|
\clearpage
|
||||||
\pagenumbering{Roman}
|
\pagenumbering{Roman}
|
||||||
|
|
||||||
\subsection{Performance analysis script}
|
\subsection{Extrait de texte}
|
||||||
\label{annex:performance}
|
|
||||||
|
|
||||||
\input{annex-performance}
|
Eng'croyable texte
|
||||||
|
|
||||||
\clearpage
|
\clearpage
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue