Calculate the MB/s from know milliseconds and bytes

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Calculate the MB/s from know milliseconds and bytes

Post by infratec »

The calculation is Ok, but the output should be

Code: Select all

Debug StrD(mymbs,3) + " MiB/s"
according to the current rules.
:mrgreen:
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Calculate the MB/s from know milliseconds and bytes

Post by Simo_na »

infratec wrote: Tue Jan 25, 2022 8:17 am Think a bit ...

2097152 bytes are nearly 2MB

If you wrote this in 0.6 seconds, the MB/s must nearly the double value and not 0.00X

Code: Select all

bytes.i = 2097152
ms.i = 653
MBs.d = bytes / ms * 1000 / 1024 / 1024

;MBs.d = bytes / ms / 1048.576

Debug MBs
Hi
leaving out for now the part that concerns the milliseconds and studying on your post.
I seem to have understood this: ((( could you confirm ? and, if both are correct, which of these should be used with ' bytes ' ? )))

Code: Select all

Global.i Bytes
Global.d MB1s,MB2s
Global.f MiBi
Global.f Mega

;base 1048.576 - Numeric ?

Bytes = 2097152

MiBi = 1048.576
MB1s = Bytes / MiBi

Debug StrD(MB1s,8)
;1999.99990501

;base 1024 - Binary ?

Mega = 1024
MB2s = Bytes / Mega

Debug StrD(MB2s,8)
;2048.00000000
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Calculate the MB/s from know milliseconds and bytes

Post by infratec »

Sorry to say that, but your Mega calculation is totally wrong,

The 1048.5 comes from:

Code: Select all

ms * 1000 / 1024 / 1024
So it is based on milliseconds and a megabyte

Your calculation is based on 1 second and furthermore you are calculating kilobytes and not megabytes.
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Calculate the MB/s from know milliseconds and bytes

Post by Simo_na »

infratec wrote: Sat Feb 12, 2022 11:49 am Your calculation is based on 1 second and furthermore you are calculating kilobytes and not megabytes.
Thank you Infratec, you gave me a good answer and I clarified my ideas

Code: Select all

mymbs = mybytes / myms * 1000 / 1024 / 1024
Debug StrD(mymbs,3) + " MB/s"
so, this is (mybytes / myms * 1000 / 1024 / 1024)

Thank you
:)
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Calculate the MB/s from know milliseconds and bytes

Post by Simo_na »

Hi
from a code of Readspeed V3.0 by @Rescator I find this:

Code: Select all

text$ + "Test took " + StrD((datestop - datestart) / 60000.0, 3) + " minutes, speed was " + StrD(totalsize / 1048576.0 / (speedsum / 1000.0), 2) + " MB/s (" + StrD(totalsize / 131072.0 / (speedsum / 1000.0), 2) + " mbit/s)." + #LF$
from this i have isolated :

Code: Select all

 StrD(totalsize / 1048576.0 / (speedsum / 1000.0), 2) + " MB/s (" + StrD(totalsize / 131072.0 / (speedsum / 1000.0), 2) + " mbit/s)."
if we take the bytes for 'totalsize' and the 'speedsum' for the milliseconds do you think it could be fine also in my case ?
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Calculate the MB/s from know milliseconds and bytes

Post by infratec »

If you look at one of my first examples you will see:

Code: Select all

bytes.i = 2097152
ms.i = 653
MBs.d = bytes / ms * 1000 / 1024 / 1024

;MBs.d = bytes / ms / 1048.576

Debug MBs
The number 1048.576 comses not from somewhere. It is calculated.

If you want I can modifiy the calculation in endless ways...

Code: Select all

bytes.i = 2097152
ms.i = 653
MBs.d = bytes / ms * 1000 / 1024 / 1024 * 11 * 10 / 110
Debug MBs
The result will always be the same.
Why are you still searching for a solution if you already have a correct one :?:
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Calculate the MB/s from know milliseconds and bytes

Post by Simo_na »

infratec wrote: Sun Feb 27, 2022 10:28 pm Why are you still searching for a solution if you already have a correct one :?:
Thank You

I try to explain myself like this:
please run this code and read the Debug :)

Code: Select all

Global.i totalsize = 2097152
Global.i speedsum = 1405
Global.d Rescator_MBs = (totalsize / 1048576 / (speedsum / 1000))
Debug "Rescator MBs = "+Rescator_MBs
Global.d Infratec_MBs = (totalsize / speedsum * 1000 / 1024 /1024)
Debug "Infratec MBs = "+Infratec_MBs
Debug "and this is ok."
Debug "But in addition we could visualize:"
Global.d Rescator_mbit_s = (totalsize / 131072 / (speedsum / 1000))
Debug "Rescator mbit/s = "+Rescator_mbit_s
Debug "Something is not right here ?"
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Calculate the MB/s from know milliseconds and bytes

Post by Simo_na »

I did some tests with the SHFileOperation function to compare the speed and verify that the Purebasic debug/nodebug reports the same speed detected by MS Windows. This code is very close from what reported speed by the MS Windows shows during operations copy. (GB/s - MB/s)

Code: Select all

bytes=FileSize("anyname.anyprefix")
gbs=bytes/total_ms*1000/1024.0/1024.0/1024.0
If gbs<1.0
gbs=0
mbs=bytes/total_ms*1000/1024.0/1024.0/1024.0
EndIf
Post Reply