Code: Select all
EnableExplicit
Procedure.s LoadFile1(Filename.s) ;SLOW!
Protected r.s
Protected f = ReadFile(#PB_Any, Filename, #PB_UTF8)
If f
r = ReadString(f, #PB_File_IgnoreEOL)
CloseFile(f)
ProcedureReturn r
EndIf
EndProcedure
Procedure.s LoadFile2(Filename.s)
Protected *p, r.s
Protected f = ReadFile(#PB_Any, Filename)
If f
*p = AllocateMemory(Lof(f), #PB_Memory_NoClear)
ReadData(f, *p, Lof(f))
CloseFile(f)
r = PeekS(*p, -1, #PB_UTF8)
FreeMemory(*p)
ProcedureReturn r
EndIf
EndProcedure
Define t1, r1, r2, r.s
t1 = ElapsedMilliseconds()
r = LoadFile1("c:\test\test1.html")
r1 = ElapsedMilliseconds() - t1
r = ""
t1 = ElapsedMilliseconds()
r = LoadFile2("c:\test\test1.html")
r2 = ElapsedMilliseconds() - t1
MessageRequester("", Str(r1) + #TAB$ + Str(r2))
File is a HTML frontpage of some site.
---------------------------
---------------------------
295 17
---------------------------
OK
---------------------------
If anything, you would expect ReadString to be faster, since no PeekS and freeing needed, but it's 17 times slower...
Seems #PB_File_IgnoreEOL doesn't make it any faster than reading lines one by one.
Also weird, seems that specifying the size with PeekS is slower than just passing -1.
// Moved from "Bugs - Windows". Slowness is not a bug. (Kiffi)