Common memory performance testing tools include Stream and Sysbench.
- Using dd for Simple Memory Read/Write Speed Test
The dd command, available by default on Linux systems, can be used to perform a simple memory performance test:
$ dd if=/dev/zero of=/dev/null bs=4096 count=1048576
1048576+0 records in
1048576+0 records out
4294967296 bytes (4.3 GB) copied, 2.69363 s, 1.6 GB/s
This measures the speed of data copying, providing a basic comparison of system memory performance.
- Stream for Memory Performance Testing
2.1 Installation
$ mkdir mem_test
$ cd mem_test
$ wget https://www.cs.virginia.edu/stream/FTP/Code/stream.c
# Or clone from a domestic source
$ git clone https://gitee.com/lldhsds/stream.git
$ cd stream/
$ gcc stream.c -O3 -fopenmp -DSTREAM_ARRAY_SIZE=1024*1024*1024 -DNTIMES=20 -mcmodel=medium -o mem_test_exec
Compilation flags explanation:
-O3: Optimization level for the compiler.-fopenmp: Enables OpenMP for multi-processor environments.-DSTREAM_ARRAY_SIZE: Sets the size of arraysa[],b[],c[].-mcmodel=medium: Required when single Memory Array Size exceeds 2GB.
2.2 Execution
$ ./mem_test_exec
-------------------------------------------------------------
STREAM version $Revision: 5.10 $
-------------------------------------------------------------
This system uses 8 bytes per array element.
-------------------------------------------------------------
Array size = 104857600 (elements), Offset = 0 (elements)
Memory per array = 800.0 MiB (= 0.8 GiB).
Total memory required = 2400.0 MiB (= 2.3 GiB).
Each kernel will be executed 20 times.
The *best* time for each kernel (excluding the first iteration)
will be used to compute the reported bandwidth.
-------------------------------------------------------------
Number of Threads requested = 4
Number of Threads counted = 4
-------------------------------------------------------------
Your clock granularity/precision appears to be 1 microseconds.
Each test below will take on the order of 29659 microseconds.
(= 29659 clock ticks)
Increase the size of the arrays if this shows that
you are not getting at least 20 clock ticks per test.
-------------------------------------------------------------
WARNING -- The above is only a rough guideline.
For best results, please be sure you know the
precision of your system timer.
-------------------------------------------------------------
Function Best Rate MB/s Avg time Min time Max time
Copy: 34701.7 0.066024 0.048347 0.084770
Scale: 39939.1 0.056470 0.042007 0.070259
Add: 41795.4 0.079521 0.060212 0.102223
Triad: 41073.6 0.079864 0.061270 0.102483
-------------------------------------------------------------
Solution Validates: avg error less than 1.000000e-13 on all three arrays
-------------------------------------------------------------
2.3 Result Analysis
Record COPY, SCALE, ADD, TRIAD values from test results. Average multiple runs for comparative analysis across different machines.
- Sysbench for Memory Performance Testing
3.1 Installation
3.1.1 Package Manager Installation
# CentOS
sudo yum -y install sysbench
# Ubuntu
sudo apt -y install sysbench
3.1.2 Source Code Compilation
$ sudo git clone https://github.com/akopytov/sysbench.git
$ cd sysbench/
$ sudo ./autogen.sh
$ sudo ./configure --without-mysql
$ sudo make && sudo make install
3.2 Execution
$ sysbench memory --threads=4 --time=60 --report-interval=1 --memory-block-size=8K --memory-total-size=100G --memory-oper=read --memory-access-mode=seq run
3.3 Result Analysis
Note the average read/write speeds. Adjust parameters, run multiple tests, and average the results.
- Memtester for Memory Correctness Testing
$ wget https://pyropus.ca./software/memtester/old-versions/memtester-4.6.0.tar.gz
$ tar xf memtester-4.6.0.tar.gz
$ cd memtester-4.6.0/
$ sudo make && sudo make install
$ sudo memtester 1G 3
- Mbw for Memory Performence Testing
$ sudo apt install -y mbw
# Or compile from source
$ sudo git clone https://github.com/raas/mbw.git
$ cd mbw
$ sudo make
$ ./mbw -q -n 10 256