Page 1 of 1
Network difference time 5.00 and 5.11b3 - only me?
Posted: Fri Mar 15, 2013 11:51 pm
by jesperbrannmark
I am trying to download a webpage with 5.11b3 and 5.00 - both x86 on os x10.8.2
Code: Select all
InitNetwork()
a=ElapsedMilliseconds()
ReceiveHTTPFile("http://purebasic.com",GetTemporaryDirectory()+Str(Random(99)))
Debug ElapsedMilliseconds()-a
Result: 5.11b3 over 10000 ms
Result: 5.00 around 150 ms
Only me?
Re: Network difference time 5.00 and 5.11b3 - only me?
Posted: Sat Mar 16, 2013 8:24 am
by jamirokwai
Confirmed, on PB 5.1, 32, Mountain Lion, it takes 10350 ms to finish downloading on my MacBook Pro.
Re: Network difference time 5.00 and 5.11b3 - only me?
Posted: Sat Mar 16, 2013 9:21 am
by jesperbrannmark
Thanks. It was in the middle of the night and I saw both my program running slower and slower (tried to update to new b3) as well as me running slower and slower. I will post a bug post
Re: Network difference time 5.00 and 5.11b3 - only me?
Posted: Sun Mar 17, 2013 7:39 am
by wilbert
You can use this as a workaround
Code: Select all
Procedure DownloadFromURL(URL.s, Filename.s)
Protected u = CocoaMessage(0, 0, "NSURL URLWithString:$", @URL)
Protected d = CocoaMessage(0, CocoaMessage(0, 0, "NSData alloc"), "initWithContentsOfURL:", u)
If d
CocoaMessage(0, d, "writeToFile:$", @Filename, "atomically:", #NO)
CocoaMessage(0, d, "release")
EndIf
ProcedureReturn d
EndProcedure
a=ElapsedMilliseconds()
DownloadFromURL("http://purebasic.com",GetTemporaryDirectory()+Str(Random(99)))
Debug ElapsedMilliseconds()-a
It does the same and doesn't require InitNetwork().
A similar procedure can be used to download to memory
Code: Select all
Procedure DownloadToMemory(URL.s)
Protected m, m_size
Protected u = CocoaMessage(0, 0, "NSURL URLWithString:$", @URL)
Protected d = CocoaMessage(0, CocoaMessage(0, 0, "NSData alloc"), "initWithContentsOfURL:", u)
If d
m_size = CocoaMessage(0, d, "length")
If m_size
m = AllocateMemory(m_size, #PB_Memory_NoClear)
If m
CocoaMessage(0, d, "getBytes:", m, "length:", m_size)
EndIf
EndIf
CocoaMessage(0, d, "release")
EndIf
ProcedureReturn m
EndProcedure
*mem = DownloadToMemory("http://purebasic.com")
*mem_size = MemorySize(*mem)
MessageRequester(Str(*mem_size) + " bytes", PeekS(*mem, *mem_size, #PB_UTF8))
FreeMemory(*mem)
Re: Network difference time 5.00 and 5.11b3 - only me?
Posted: Sun Mar 17, 2013 9:10 am
by jesperbrannmark
Can it be threaded? Right now i dont get "DONE" in debug....
Code: Select all
Procedure DownloadFromURL(i)
Debug Str(i)+ " STARTED"
Protected url.s="http://purebasic.com"
Protected filename.s=GetTemporaryDirectory()+Str(Random(99))
Protected u = CocoaMessage(0, 0, "NSURL URLWithString:$", @URL)
Protected d = CocoaMessage(0, CocoaMessage(0, 0, "NSData alloc"), "initWithContentsOfURL:", u)
If d
CocoaMessage(0, d, "writeToFile:$", @Filename, "atomically:", #NO)
CocoaMessage(0, d, "release")
EndIf
Debug Str(i)+ " DONE"
ProcedureReturn d
EndProcedure
For i=1 To 10
CreateThread(@DownloadFromURL(),i)
Next
Re: Network difference time 5.00 and 5.11b3 - only me?
Posted: Sun Mar 17, 2013 12:02 pm
by wilbert
jesperbrannmark wrote:Can it be threaded? Right now i dont get "DONE" in debug....
It doesn't have the time to finish.
If you put a long enough Delay() after the loop that creates the threads, it should work.