PowerBasic vs. PureBasic with Random Files

Started by Israel Vega, March 13, 2013, 05:28:44 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Israel Vega

Already got PureBasic license and am learning to use the compiler. It is very different because PowerBasic is very readable and easy to understand. I find it the compiler has many good things. I've been learning as when buying a license PowerBasic, also every time I like PureBasic. There is a function PARSE$ but there is a function Stringfield almost equal. There is no OPEN statement as the traditional Basic, but you can open a file as RANDOM mode with OpenFile () and CreateFile().

I did a test with files RANDOM and PowerBasic  is better that PureBasic in speed. With my I7 processor

PureBasic 1404 milliseconds and PowerBasic 750 milliseconds. 

PowerBasic code:

#COMPILE EXE

TYPE EMPLOYEESX
  CODE AS STRING * 10
  NAME AS STRING * 60
END TYPE
GLOBAL EMPLOYEES AS EMPLOYEESX

FUNCTION PBMAIN
    INICIO#=TIMER
    KILL "C:\PUREBASIC5\RANDOM\RANDOM_PB.DAT"
    OPEN "C:\PUREBASIC5\RANDOM\RANDOM_PB.DAT" FOR RANDOM AS #1 LEN=LEN(EMPLOYEES)
    FOR X&=1 TO 100000
       LSET EMPLOYEES.CODE=STR$(X&)
       LSET EMPLOYEES.NAME="israel"+STR$(X&)
       PUT #1,X&,EMPLOYEES
    NEXT X&
    CLOSE #1
    FINAL#=TIMER
    MSGBOX "End Process Elapsed Time: "+STR$((final#-inicio#)*1000)

END FUNCTION




PureBasic code:

Structure EMPLOYEES
  code.s{10}
  name.s{60}
EndStructure

Declare UpdateEmployeeRecord(file, record_number, *record.EMPLOYEES)
Declare ReadEmployeeRecord(file, record_number)

StartTime = ElapsedMilliseconds()

With employee.EMPLOYEES
  \code = ""
  \name = ""
EndWith

If CreateFile(0, "C:\PUREBASIC5\RANDOM\employees.dat")
  For i=1 To 1 * SizeOf(EMPLOYEES)
    WriteByte(0, 0)
  Next i
  CloseFile(0)
EndIf



If OpenFile(0, "C:\PUREBASIC5\RANDOM\employees.dat")
For i=1 To 100000
With employee.EMPLOYEES
\code = Str(I)
\name = "israel"+Str(i)
EndWith     
   UpdateEmployeeRecord(0, i, @employee)
Next I

EndIf   

CloseFile(0)


finalTime = ElapsedMilliseconds()

MessageRequester("",Str(finaltime-starttime))

End

Procedure ReadEmployeeRecord(file, record_number)
  *result.EMPLOYEES = AllocateMemory(SizeOf(EMPLOYEES))
  FileSeek(file, record_number * SizeOf(EMPLOYEES))
  If ReadData(file, *result, SizeOf(EMPLOYEES)) = SizeOf(EMPLOYEES)
    ProcedureReturn *result
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

Procedure UpdateEmployeeRecord(file, record_number, *record.EMPLOYEES)
  FileSeek(file, record_number * SizeOf(EMPLOYEES))
  If WriteData(file, @*record\code, SizeOf(employees\code)) = SizeOf(employees\code) And
     WriteData(file, @*record\name, SizeOf(employees\name)) = SizeOf(employees\name)
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure



May be more code in PureBasic?...but not exist a sentence OPEN FOR RANDOM or OPEN FOR BINARY...may be I am mixed pear with apple?...

I love the simplicity of PowerBasic and execution speed ... I'm just looking for an alternative... Is a shame that updates are PowerBasic takes so long to get there ... and that only exists only in Windows environment.

I not know that future of PowerBasic...I am found in PureBasic forum, some programmers who migrated from gfaBASIC ...a compiler dead. http://bluez.home.xs4all.nl/datatalk/gfabasic%201.htm#top

I can take the best of the two, if I need a 64 bits application or compile to Mac or Linux, I can use PureBasic, if not ... I'll PowerBasic.

Theo Gottwald

Yes, i can second all your results.
We had a dsicussion on this topic, here:
x64-Alternatives

At this time Jim regularly shows the flag to proof that PowerBasic is alive.
I hope that this will really be the case.
At least as long as x32 is usable for anything.

At this time i do not believe in PB to have something for x64 in any foreseable future.
Just my personal assumtion, from the fact how long it takes to even make small changes in x32.