diff --git a/latex/annex-performance.tex b/latex/annex-performance.tex new file mode 100644 index 0000000..b3170e2 --- /dev/null +++ b/latex/annex-performance.tex @@ -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} diff --git a/latex/content.tex b/latex/content.tex index ce97cad..aa0432a 100644 --- a/latex/content.tex +++ b/latex/content.tex @@ -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 diff --git a/latex/main.tex b/latex/main.tex index 33e1561..521dcab 100644 --- a/latex/main.tex +++ b/latex/main.tex @@ -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