## 3 Algorithms to Improve the Data Write Rate
### Data Write Performance Tests Using Binary Formats  
Using the same HDD, a series of tests adopting various writing approaches were performed to identify the most optimal data-writing algorithm. Prior to each test, a data pack was created comprising several one-dimensional byte arrays, totaling 5 GB (5,368,709,120 bytes). The tests utilized the FileStream class [31] from the System.IO namespace, which is a widely used and efficient approach to write a sequence of bytes to a file stream. The entire dataset can be written to either a single file or multiple files of equal size.  
2.1 Approach 1. Writing the Values into Files Immediately after They Are Acquired Using Internal Buffers  
The measurement typically begins by creating a new blank file. The sensor reading values are then continuously written into this file as soon as they are acquired. The file is eventually closed when the measurement is complete. This process can be repeated for multiple measurements. The testing procedure involved the following steps:  
* Step 1: A new blank file was created.
* Step 2: Overall, 1 MB of data was read from the data pack and written into the data file. This step simulates the process of acquiring the sensor reading values and then writing them into a file. This step was repeated until the file size reached 128 MB.
* Step 3: The current file was closed, and the process was started again from Step 1. A new file was created to save the data.
* The process was repeated from Step 2 until the entire 5 GB of data had been written. In this manner, the entire dataset was written into multiple equal-sized 128 MB files, each named in the format \"DATA-xxx.bin\", where \"xxx\" is the file number (e.g., \"DATA-001.bin\", \"DATA-002.bin\", etc.).  
In fact, when data are written into a file, they are not immediately stored on a physical disk. Instead, they are temporarily copied into the buffer memory. A buffer can be understood as a \"waiting area\" for data before writing. It refers to a chunk of memory (typically in RAM) where the data are temporarily gathered. Data that arrive earlier must wait for a certain amount of data to arrive before being sent for storage in a file. When a new file is created, an internal buffer of a configurable size is generated. If no specific buffer size is specified, the default buffer size is used during the writing process. Various buffer configurations were employed for testing, as outlined below.  
**Option 1: Using the default buffer size**. The default buffer size used was 4096 bytes. As described in Step 2, the size of the data acquired for each write was 1 MB, which was larger than the buffer size. With this configuration, the data were written immediately into the files for every 1 MB acquired. The write performance is illustrated in Figure 4. The average data write rate was 124 MB/s.  
In another test, the size of each file was increased to 256 MB, resulting in an average data write rate of 125 MB/s. Additional tests were conducted using the following configurations:  
* Increasing the size of each file to 512 MB.
* Increasing the read data chunk size to 5, 10, and 20 MB.  
Nevertheless, these tests did not reveal any notable difference in write performance.  
**Option 2: Using a configured buffer size**. Similar to the previous tests, the file size was first configured to 128 MB, and then to 256 MB. The buffer sizes were 8, 16, 32, 64, 128, and 256 MB. With these configurations, the acquired data were temporarily gathered in buffers until sufficient data were accumulated for writing into the files. The results indicated that larger buffer sizes resulted in a better write performance for the same file size configuration. For each file size setting, the best performance was achieved when the buffer size matched the file size. The average write speeds were 150 and 154 MB/s for buffer sizes of 128 and 256 MB, respectively, as illustrated in Figure 5. However, setting the buffer size larger than the file size did not yield any significant improvements.