tex: add performance analysis annex

這個提交存在於:
Paul ALNET 2023-06-03 17:25:08 +02:00
父節點 00cc5befc7
當前提交 87a8bbbf0f
共有 3 個檔案被更改,包括 61 行新增3 行删除

57
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}

查看文件

@ -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 X.} \footnotetext{The full code used to measure performance can be found in Annex \ref{annex:performance}.}
% TODO annex % TODO annex
\paragraph{Intuitive algorithm} Store values first, calculate later \paragraph{Intuitive algorithm} Store values first, calculate later

查看文件

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