Hi guys,
I wondered how fast Memblocks and Arrays are when being created, having large values written to them and being read again, so I threw together a program to test this.
//memblock vs Array
/*
It is the goal of this program to test the creation speed, data write, and data read of memblocks vs arrays when writing integers
this program works in 3 stages
1) creation
2) write
3) read
*/
SetVirtualResolution( 720, 1280 )
Size = 10000000
Print( "Please wait while program runs." )
Print( "This may take a few minutes." )
Print( "" )
Print( "Running Memblock creation time text")
Sync()
// timer setup
//Memblock tests
basetime# = timer() //get the time this command is executed.
memblock = CreateMemblock( Size * 4 ) //each integer takes 4 bytes
Memblock_Creation_Time# = timer() - basetime# : print( "Memblock Creation time complete") : Print("Running Memblock Write Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size * 4 - 4 step 4
SetMemblockInt( memblock, i, 2147483647 )
Next i
Memblock_Write_Time# = Timer() - basetime# : print( "Memblock Write time complete") : Print("Running Memblock Read Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size * 4 - 4 step 4
read = GetMemblockInt( memblock, i )
Next i
Memblock_Read_Time# = Timer() - basetime# : print( "Memblock Read time complete") : Print("Running Array Creation Test") : Sync() : basetime# = timer() //reset the timer
//Array tests
Dim MyArray[ size ]
Array_Creation_Time# = timer() - basetime# : print( "Array Creation time complete") : Print("Running Array Write Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size - 1
MyArray[ i ] = 2147483647
Next i
Array_Write_Time# = Timer() - basetime# : print( "Array Write time complete") : Print("Running Array Read Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size - 1
read = MyArray[ i ]
Next i
Array_Read_Time# = Timer() - basetime# : print( "Array Read time complete") : Print("Running Memblock Float Creation Test") : Sync()
// *********** Float Test **************
//Memblock tests
basetime# = timer() //get the time this command is executed.
memblockf = CreateMemblock( Size * 4 ) //each integer takes 4 bytes
Memblock_Creation_Time_f# = timer() - basetime# : print( "Memblock Creation time complete") : Print("Running Memblock Write Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size * 4 - 4 step 4
SetMemblockFloat( memblockf, i, 999.9999 )
Next i
Memblock_Write_Time_f# = Timer() - basetime# : print( "Memblock Write time complete") : Print("Running Memblock Read Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size * 4 - 4 step 4
read# = GetMemblockFloat( memblockf, i )
Next i
Memblock_Read_Time_f# = Timer() - basetime# : print( "Memblock Read time complete") : Print("Running Array Creation Test") : Sync() : basetime# = timer() //reset the timer
//Array Tests
Dim MyArrayf[ size ] as float
Array_Creation_Time_f# = timer() - basetime# : print( "Array Creation time complete") : Print("Running Array Write Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size - 1
MyArrayf[ i ] = 999.9999
Next i
Array_Write_Time_f# = Timer() - basetime# : print( "Array Write time complete") : Print("Running Array Read Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size - 1
read# = MyArrayf[ i ]
Next i
Array_Read_Time_f# = Timer() - basetime# : print( "Array Read time complete") : Print("Running Memblock Byte Creation Test") : Sync()
// *********** Byte Test **************
//Memblock tests
basetime# = timer() //get the time this command is executed.
memblockb = CreateMemblock( Size ) //each integer takes 4 bytes
Memblock_Creation_Time_b# = timer() - basetime# : print( "Memblock Creation time complete") : Print("Running Memblock Write Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size -1
SetMemblockByte( memblockb, i, 255 )
Next i
Memblock_Write_Time_b# = Timer() - basetime# : print( "Memblock Write time complete") : Print("Running Memblock Read Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size - 1
read = GetMemblockByte( memblockb, i )
Next i
Memblock_Read_Time_b# = Timer() - basetime# : print( "Memblock Read time complete") : Print("Running Array Creation Test") : Sync() : basetime# = timer() //reset the timer
//Array tests
Dim MyArrayb[ size ] as float
Array_Creation_Time_b# = timer() - basetime# : print( "Array Creation time complete") : Print("Running Array Write Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size - 1
MyArrayb[ i ] = 255
Next i
Array_Write_Time_b# = Timer() - basetime# : print( "Array Write time complete") : Print("Running Array Read Test") : Sync() : basetime# = timer() //reset the timer
For i = 0 to Size - 1
read = MyArrayb[ i ]
Next i
Array_Read_Time_b# = Timer() - basetime# : print( "Array Read time complete") : Print("Running Memblock Byte Creation Test") : Sync()
// Tests are over, this is just for data dumping and exit.
AddVirtualButton( 1, 200, 1080, 200 )
AddVirtualButton( 2, 425, 1080, 200 )
SetVirtualButtonText( 1, "Dump" )
SetVirtualButtonText( 2, "Exit" )
//Clear up the memory!!
UnDim MyArray[]
UnDim MyArrayf[]
UnDim MyArrayb[]
DeleteMemblock( memblock )
DeleteMemblock( memblockf )
DeleteMemblock( memblockb )
Do
Print( "Integer Test")
Print( "" )
Print( "Memblock Create time: " + str( Memblock_Creation_Time# ) )
Print( "Memblock Write time: " + str( Memblock_Write_Time# ) )
Print( "Memblock Read time: " + str( Memblock_Read_Time# ) )
Print( "" )
Print( "Array Create time: " + str( Array_Creation_Time# ) )
Print( "Array Write time: " + str( Array_Write_Time# ) )
Print( "Array Read time: " + str( Array_Read_Time# ) )
Print( "" )
Print( "Float test" )
Print( "")
Print( "Memblock Create time: " + str( Memblock_Creation_Time_f# ) )
Print( "Memblock Write time: " + str( Memblock_Write_Time_f# ) )
Print( "Memblock Read time: " + str( Memblock_Read_Time_f# ) )
Print( "" )
Print( "Array Create time: " + str( Array_Creation_Time_f# ) )
Print( "Array Write time: " + str( Array_Write_Time_f# ) )
Print( "Array Read time: " + str( Array_Read_Time_f# ) )
Print( "" )
Print( "Byte test" )
Print( "")
Print( "Memblock Create time: " + str( Memblock_Creation_Time_b# ) )
Print( "Memblock Write time: " + str( Memblock_Write_Time_b# ) )
Print( "Memblock Read time: " + str( Memblock_Read_Time_b# ) )
Print( "" )
Print( "Array Create time: " + str( Array_Creation_Time_b# ) )
Print( "Array Write time: " + str( Array_Write_Time_b# ) )
Print( "Array Read time: " + str( Array_Read_Time_b# ) )
If GetRawKeystate( 27 ) = 1 then End
If GetVirtualButtonPressed( 1 ) = 1
If GetFileExists( "dump.txt" ) = 1 then DeleteFile( "dump.txt" )
File = OpenToWrite( "dump.txt" )
WriteLine( File, "Memory space used: " + str( Size ) )
WriteLine( File, "" )
WriteLine( File, "Integer Test")
WriteLine( File, "" )
WriteLine( File, "Memblock Create time: " + str( Memblock_Creation_Time# ) )
WriteLine( File, "Memblock Write time: " + str( Memblock_Write_Time# ) )
WriteLine( File, "Memblock Read time: " + str( Memblock_Read_Time# ) )
WriteLine( File, "" )
WriteLine( File, "Array Create time: " + str( Array_Creation_Time# ) )
WriteLine( File, "Array Write time: " + str( Array_Write_Time# ) )
WriteLine( File, "Array Read time: " + str( Array_Read_Time# ) )
WriteLine( File, "" )
WriteLine( File, "Float test" )
WriteLine( File, "")
WriteLine( File, "Memblock Create time: " + str( Memblock_Creation_Time_f# ) )
WriteLine( File, "Memblock Write time: " + str( Memblock_Write_Time_f# ) )
WriteLine( File, "Memblock Read time: " + str( Memblock_Read_Time_f# ) )
WriteLine( File, "" )
WriteLine( File, "Array Create time: " + str( Array_Creation_Time_f# ) )
WriteLine( File, "Array Write time: " + str( Array_Write_Time_f# ) )
WriteLine( File, "Array Read time: " + str( Array_Read_Time_f# ) )
WriteLine( File, "" )
WriteLine( File, "Byte test" )
WriteLine( File, "")
WriteLine( File, "Memblock Create time: " + str( Memblock_Creation_Time_b# ) )
WriteLine( File, "Memblock Write time: " + str( Memblock_Write_Time_b# ) )
WriteLine( File, "Memblock Read time: " + str( Memblock_Read_Time_b# ) )
WriteLine( File, "" )
WriteLine( File, "Array Create time: " + str( Array_Creation_Time_b# ) )
WriteLine( File, "Array Write time: " + str( Array_Write_Time_b# ) )
WriteLine( File, "Array Read time: " + str( Array_Read_Time_b# ) )
CloseFile( File )
Do
Print("Data dumped, tap screen or click mouse to continue.")
If GetPointerPressed() = 1 then Exit
Sync()
Loop
EndIf
If GetVirtualButtonPressed( 2 ) = 1
End
EndIf
Sync()
Loop
If you have any suggestions for improvement, or see any problems with my methods please feel free to comment. I\'m also running these on various hardware to see the difference in memory performance.
PC Data dump (AMD X4 640 CPU, 6GB DDR3 PC-12800 RAM, Windows 8 64-bit OS, AMD 6670 1GB GPU, Kingston 256GB SSD, Samsung Spinpoint 1TB, 320GB 2.5inch laptop drive, 160GB 2.5inch laptop drive):
Memory space used: 10000000
Integer Test
Memblock Create time: 0.000107
Memblock Write time: 1.505386
Memblock Read time: 1.485203
Array Create time: 0.029549
Array Write time: 1.453180
Array Read time: 1.384452
Float test
Memblock Create time: 0.000096
Memblock Write time: 1.473124
Memblock Read time: 1.436158
Array Create time: 0.030880
Array Write time: 1.395630
Array Read time: 1.693573
Byte test
Memblock Create time: 0.000043
Memblock Write time: 1.183435
Memblock Read time: 1.136839
Array Create time: 0.029850
Array Write time: 1.532400
Array Read time: 1.520491
My Sony Xperia Play R800i gives
Memory space used: 10000000
Integer Test
Memblock Create time: 0.000122
Memblock Write time: 11.701599
Memblock Read time: 12.199646
Array Create time: 0.105591
Array Write time: 11.373657
Array Read time: 11.849426
Float test
Memblock Create time: 0.000122
Memblock Write time: 11.692627
Memblock Read time: 12.416077
Array Create time: 4.897461
Array Write time: 12.048096
Array Read time: 11.533875
Byte test
Memblock Create time: 0.000061
Memblock Write time: 9.940247
Memblock Read time: 10.547852
Array Create time: 0.515137
Array Write time: 14.044067
Array Read time: 15.689270