text writefile bmax blitz3d

BlitzMax Forums/BlitzMax Programming/text writefile bmax blitz3d

mongia2(Posted 2007) [#1]
bmax in my computer

2700
2800

blitz3d
1670
1600




code: bmax

Global pix_r[2001,2001]
Global pix_g[2001,2001]
Global pix_b[2001,2001]


te=MilliSecs()

file=WriteFile("bla.txt")

maxx=2000

For nx=0 To maxx
For ny=0 To maxx

WriteByte file,pix_r[nx,ny]
WriteByte file,pix_g[nx,ny]
WriteByte file,pix_b[nx,ny]


Next
Next

CloseFile file

Print (MilliSecs()-te)


te=MilliSecs()

file=ReadFile("bla.txt")

maxx=2000

For nx=0 To maxx
For ny=0 To maxx

pix_r[nx,ny]=ReadByte(file)
pix_g[nx,ny]=ReadByte(file)

pix_b[nx,ny]=ReadByte(file)



Next
Next

CloseFile file

Print (MilliSecs()-te)

code blitz3d

dim pix_r(2000,2000)
dim pix_g(2000,2000)
dim pix_b(2000,2000)


te=millisecs()

file=writefile("bb.txt")

maxx=2000

for nx=0 to maxx
for ny=0 to maxx

writebyte(file,pix_r(nx,ny))
writebyte(file,pix_g(nx,ny))
writebyte(file,pix_b(nx,ny))

next
next



closefile file

print (millisecs()-te)



te=millisecs()

file=readfile("bb.txt")


for nx=0 to maxx
for ny=0 to maxx

pix_r(nx,ny)=readbyte(file)
pix_g(nx,ny)=readbyte(file)
pix_b(nx,ny)=readbyte(file)



next
next



closefile file

print (millisecs()-te)


waitkey


tonyg(Posted 2007) [#2]
Might be quicker in Bmax if you use writestream/readstream into a TStream rather than use integer handles. You should really be setting superstrict as well and, perhaps, setting local scope.
It saves about 500ms on my system. Haven't got B3D available at the moment to check.


degac(Posted 2007) [#3]
SuperStrict

Global pix_r:Byte[2001,2001]
Global pix_g:Byte[2001,2001]
Global pix_b:Byte[2001,2001]

Local te:Int=MilliSecs()
Local file:tstream=WriteStream("bla.txt")
Local maxx:Int=2000

For Local nx:Int=0 To maxx
For Local ny:Int=0 To maxx
	WriteByte file,pix_r[nx,ny]
	WriteByte file,pix_g[nx,ny]
	WriteByte file,pix_b[nx,ny]
Next
Next

CloseStream file
Print (MilliSecs()-te)

Local te1:Int=MilliSecs()
Local file1:tstream=ReadStream("bla.txt")

For Local nx1:Int=0 To maxx
For Local ny1:Int=0 To maxx
	pix_r[nx1,ny1]=ReadByte(file1)
	pix_g[nx1,ny1]=ReadByte(file1)
	pix_b[nx1,ny1]=ReadByte(file1)
Next
Next
CloseStream file1
Print (MilliSecs()-te1)


Bmax : 2231 - 2310
Blitz3d: 1460 - 1628


Brucey(Posted 2007) [#4]
If you are going to all that effort to save it.. why not use a bank ?

SuperStrict

Global pix_r:Byte[2001,2001]
Global pix_g:Byte[2001,2001]
Global pix_b:Byte[2001,2001]

Local te:Int=MilliSecs()

Local maxx:Int=2001

Local bank:TBank = CreateBank(maxx * maxx * 3)

For Local nx:Int=0 Until maxx

	Local nxp:Int = nx * (maxx * 3)

	For Local ny:Int=0 Until maxx

		bank.pokebyte(nxp + ny, pix_r[nx,ny])
		bank.pokebyte(nxp + ny + 1, pix_g[nx,ny])
		bank.pokebyte(nxp + ny + 2, pix_b[nx,ny])

	Next
Next

SaveBank(bank, "bla.txt")
bank = Null

Print (MilliSecs()-te)

Local te1:Int=MilliSecs()

Local bank1:TBank = LoadBank("bla.txt")

For Local nx1:Int=0 Until maxx

	Local nxp:Int = nx1 * (maxx * 3)

	For Local ny1:Int=0 Until maxx

		pix_r[nx1,ny1]= bank1.peekbyte(nxp + ny1)
		pix_g[nx1,ny1]= bank1.peekbyte(nxp + ny1 + 1)
		pix_b[nx1,ny1]= bank1.peekbyte(nxp + ny1 + 2)

	Next
Next

Print (MilliSecs()-te1)



tonyg(Posted 2007) [#5]
. scrub that. It doesn't work properly.


marksibly(Posted 2007) [#6]
Hi,

Stream operations in Max will be a little slower than in b3d, mainly because they are far more flexible.

The best solution is to try and write at much as possible at once - eg: instead of writing the pixels of a pixmap one at a time, write entire rows.

If you really need more speed and are only interested in reading/writing files, you might want to look at fopen_, fread_, fwrite_, fclose_ etc in the Pub.StdC module.


degac(Posted 2007) [#7]
Thanks!