\chapter{Benchmarking}
\label{chapter:benchmarking}
This chapter will research the real world capabilities of MagSend. I attempt to transmit a message using different speeds of MagSend under different system CPU loads to see how it performs and which transfer speed is the most reliable to use.

The following benchmark tests are all structured in the same way. I run each test 5 times to get a more accurate view of the test. For each test, I wrote down if MagSend can detect the preamble, the received payload length, the received message, and whether the \gls{crc} is valid.

The message used in the test transmissions is "\textbf{Test}".


\section{Idle CPU Load}
The following benchmarks were run during idle CPU Load, which was about 1-5\% utilization.

\subsection{\SI{0.5}{\bit\per\second}}
\begin{table}[H]
    \begin{bfhTabular}{l l l l l}
        Run & Preamble Detected & Payload Length & Is CRC Valid & Received Message \\
        1 & Yes & \SI{4}{\byte} & No & Vêÿ\\
        2 & Yes & \SI{4}{\byte} & Yes & Test \\
        3 & Yes & \SI{4}{\byte} & Yes & Test\\
        4 & Yes & \SI{4}{\byte} & Yes & Test \\
        5 & Yes & \SI{4}{\byte} & No & {\textunderscore}rÛ
    \end{bfhTabular}
    \caption{Benchmark - Idle CPU Load - \SI{0.5}{\bit\per\second}}
\end{table}

\subsection{\SI{1}{\bit\per\second}}
\begin{table}[H]
    \begin{bfhTabular}{l l l l l}
        Run & Preamble Detected & Payload Length & Is CRC Valid & Received Message \\
        1 & Yes & \SI{4}{\byte} & Yes  & Test\\
        2 & Yes & \SI{4}{\byte} & No  & Test\\
        3 & Yes & \SI{4}{\byte} & Yes & Test\\
        4 & Yes & \SI{4}{\byte} & Yes  & Test\\
        5 & Yes & \SI{4}{\byte} & No & TÊæé
    \end{bfhTabular}
    \caption{Benchmark - Idle CPU Load - \SI{1}{\bit\per\second}}
\end{table}

\section{25\% CPU Load}
The following benchmarks were run with 25\% CPU utilization. The tool \texttt{stress} was used to put a load on the CPU \cite{stress}.

\subsection{\SI{0.5}{\bit\per\second}}
\begin{table}[H]
    \begin{bfhTabular}{l l l l l}
        Run & Preamble Detected & Payload Length & Is CRC Valid & Received Message \\
        1 & Yes & N/A & No & N/A\\
        2 & Yes & \SI{4}{\byte} & No & N/A\\
        3 & No & N/A & No & N/A\\
        4 & No & N/A & No & N/A\\
        5 & No & N/A & No & N/A\\
    \end{bfhTabular}
    \caption{Benchmark - 25\% CPU Load - \SI{0.5}{\bit\per\second}}
\end{table}

\subsection{\SI{1}{\bit\per\second}}
\begin{table}[H]
    \begin{bfhTabular}{l l l l l}
        Run & Preamble Detected & Payload Length & Is CRC Valid & Received Message \\
        1 & No & N/A & No & N/A\\
        2 & Yes & N/A & No & N/A\\
        3 & No & N/A & No & N/A\\
        4 & No & N/A & No & N/A\\
        5 & No & N/A & No & N/A
    \end{bfhTabular}
    \caption{Benchmark - 25\% CPU Load - \SI{1}{\bit\per\second}}
\end{table}

\subsection{Results}
As one can see in the benchmarks, the most successful configuration was running MagSend with \SI{1}{\bit\per\second} at with an idle CPU followed by \SI{0.5}{\bit\per\second} at an idle CPU.

The benchmarks with 25\% CPU load were mostly failing, with a few being able to detect the preamble, and one even being able to receive the payload length from the message. There might be a few reasons why the results are like this. The first one is thermal throttling (see \autoref{section:thermal_throttling}).

The laptop that was used for running the benchmarks already reaches CPU temperatures of over \SI{90}{\celsius} when only running at around 25\% CPU load (see \autoref{figure:cpu_temperatures}).

\begin{figure}[H]
    \fbox{\includegraphics[width=1\textwidth]{benchmarking/cpu_temperatures.png}}
    \caption{CPU temperatures under 25\% CPU load}
    \label{figure:cpu_temperatures}
\end{figure}

The other problem with the failing benchmarks is on the receiving side. The interval at which the sensor provides data to the application is not guaranteed and thus introduces some jitter \cite{androidSensorMonitor}, which is not yet handled perfectly in the app.
