Compare commits

..

2 commits

Author SHA1 Message Date
Paul ALNET
87a8bbbf0f tex: add performance analysis annex 2023-06-03 17:25:08 +02:00
Paul ALNET
00cc5befc7 chore: remove invisible ~ 2023-06-03 17:11:15 +02:00
3 changed files with 65 additions and 7 deletions

View file

@ -0,0 +1,57 @@
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}

View file

@ -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
numbers. We wrote the following algorithms \footnotemark :
\footnotetext{The full code used to measure performance can be found in Annex X.}
\footnotetext{The full code used to measure performance can be found in Annex \ref{annex:performance}.}
% TODO annex
\paragraph{Intuitive algorithm} Store values first, calculate later
@ -166,9 +166,9 @@ mean = mean(values)
variance = variance(values)
\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
@ -184,9 +184,9 @@ mean = Tot / N
variance = Tot2 / (N-1) - mean**2
\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
the statistics on the fly. Furthermore, something we hadn't anticipated is the

View file

@ -106,9 +106,10 @@
\clearpage
\pagenumbering{Roman}
\subsection{Extrait de texte}
\subsection{Performance analysis script}
\label{annex:performance}
Eng'croyable texte
\input{annex-performance}
\clearpage