DEV Community

Discussion on: Demystifying Computers: RAM (Random Access Memory)

Collapse
 
yjdoc2 profile image
YJDoc2 • Edited

Hey, great article series 👍
Is it possible that python interpreter might be caching/not gc the file from memory as the code is using it repeatedly and the access time that is shown is actually less (code is faster) than what opening and reading the file 100 times would actually amount to?
I get the point you are making in the article 😅 , but just curious 😁

Collapse
 
gmelodie profile image
Gabriel Cruz (he/him) • Edited

Hey there! Thank you for the comment :D

So I think python has some optimizations for that, so I've done some further testing:

Time:   0.000081778s
Time:   0.000053406s
Time:   0.000043392s
Time:   0.000041962s
Time:   0.000038385s
Time:   0.000038147s
Time:   0.000038147s
Time:   0.000037670s
...
Time:   0.000033379s
Time:   0.000033379s
Time:   0.000033855s
Time:   0.000033379s
Time:   0.000033617s
Time:   0.000033379s
Enter fullscreen mode Exit fullscreen mode

So as you can see the first call is about 3 times slower than the average. I'd say it's fair to assume that, even though some dark magic might be happening, it's not all that relevant to our experiment, but I'm not sure where this difference is coming from (perhaps some material for another post? 😄)