Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4834

Beginners • Re: Memory access time Pi5

$
0
0
I am certainly doing things wrong somewhere because RAM access "should be" ten time shorter.
You are almost certainly doing something wrong and the difference can often be a lot more than that.

This is the time taken to create a 100MB file in my home directory on SD Card ...

Code:

pi@Pi3B:~ $ dd bs=1M count=100 if=/dev/zero of=./100MB.bin100+0 records in100+0 records out104857600 bytes (105 MB, 100 MiB) copied, 31.2755 s, 3.4 MB/s
And this is the time taken to create the same 100MB file in '/tmp' which is a RAM Disk ...

Code:

pi@Pi3B:~ $ dd bs=1M count=100 if=/dev/zero of=/tmp/100MB.bin100+0 records in100+0 records out104857600 bytes (105 MB, 100 MiB) copied, 0.348941 s, 301 MB/s
That's about 100 times quicker copying to RAM Disk than my SD Card. The actual difference will depend on Pi and SD Card used.

Code:

            .-----------.--------.------------.            |  Seconds  |  MB/s  |  Per byte  | .----------|-----------|--------|------------| | SD Card  |  31.2755  |    3.4 |  298.2 ns  | | Ram Disk |   0.3489  |  301   |    3.3 ns  | `----------^-----------^--------^------------'
When you do it in Python, for example ...

Code:

import timepayload_100MB = bytearray(100 * 1024 * 1024)def Write_100MB(file):    s = time.time()    with open(file, "wb") as f:        f.write(payload_100MB)    e = time.time()    print("{} \t = {:5.3f} seconds".format(file, e - s))Write_100MB("./100MB.bin")Write_100MB("/tmp/100MB.bin")
There seems to be a lot less difference -

Code:

pi@Pi3B:~ $ python3 write_110MB.py./100MB.bin      = 0.718 seconds/tmp/100MB.bin   = 0.250 seconds
But that's because you are not measuring write speed, you are more likely measuring time it takes to pass the payload to the OS to do the write.

I'm not sure exactly what you are trying to measure or why. Write to RAM will be a lot quicker than write to SD Card.

Statistics: Posted by hippy — Sun Jul 28, 2024 2:16 pm



Viewing all articles
Browse latest Browse all 4834

Trending Articles