Network difference time 5.00 and 5.11b3 - only me?

Mac OSX specific forum
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Network difference time 5.00 and 5.11b3 - only me?

Post 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?
jamirokwai
Addict
Addict
Posts: 802
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Network difference time 5.00 and 5.11b3 - only me?

Post by jamirokwai »

Confirmed, on PB 5.1, 32, Mountain Lion, it takes 10350 ms to finish downloading on my MacBook Pro.
Regards,
JamiroKwai
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Network difference time 5.00 and 5.11b3 - only me?

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Network difference time 5.00 and 5.11b3 - only me?

Post 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)
Windows (x64)
Raspberry Pi OS (Arm64)
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Network difference time 5.00 and 5.11b3 - only me?

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Network difference time 5.00 and 5.11b3 - only me?

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply