Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Test hd write speed
This example is the version from Tue, 1st Oct 2012.
Project "Test hd write speed.xojo_binary_project"
Class Window1 Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
startwrite
End EventHandler
End Control
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
startread
End EventHandler
End Control
Control EditField1 Inherits TextField
ControlInstance EditField1 Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
EventHandler Sub Close()
if f<>Nil and f.exists then
f.delete
end if
End EventHandler
EventHandler Sub Open()
dim t as textoutputStream
f=selectfolder
if f=nil then
quit
end if
f=f.child("temp")
End EventHandler
Sub startread()
dim m as memoryBlock
dim s as string
dim i,size as integer
dim su,n as integer
dim l as LargeBinaryStreamMBS
const count=10 // how often to test
size=val(editfield1.text)*1024.0*1024.0
l=f.OpenAsLargeBinaryStreamMBS(true)
if l<>nil then
ProgressBar1.value=0
ProgressBar1.maximum=100*count
for i=1 to count
testread l,size/100
next
l.close
n=ubound(r)
for i=1 to n
listBox1.addrow str(i)
su=su+r(i)
listBox1.cell(listBox1.lastIndex,1)=format(size/(r(i)/60.0)/1024.0/1024.0,"0.0")+" MB/s"
listBox1.cell(listBox1.lastIndex,2)="Read"
next
listBox1.addrow "Average ->"
listBox1.cell(listBox1.lastIndex,1)=format(count*size/(su/60.0)/1024.0/1024.0,"0.0")+" MB/s"
listBox1.cell(listBox1.lastIndex,2)="Read"
else
msgBox "File Open Error!"
end if
End Sub
Sub startwrite()
dim t as textoutputStream
dim m as memoryBlock
dim s as string
dim n,i as integer
dim su as integer
dim size as integer
const count=10 // how often to test
size=val(editfield1.text)*1024.0*1024.0
m=newmemoryBlock(size/100)
s=m.stringValue(0,size/100)
ProgressBar1.value=0
ProgressBar1.maximum=100*count
for i=1 to count
testwrite f,s
next
n=ubound(r)
for i=1 to n
listBox1.addrow str(i)
su=su+r(i)
listBox1.cell(listBox1.lastIndex,1)=format(size/(r(i)/60.0)/1024.0/1024.0,"0.0")+" MB/s"
listBox1.cell(listBox1.lastIndex,2)="Write"
next
listBox1.addrow "Average ->"
listBox1.cell(listBox1.lastIndex,1)=format(count*size/(su/60.0)/1024.0/1024.0,"0.0")+" MB/s"
listBox1.cell(listBox1.lastIndex,2)="Write"
End Sub
Sub testread(l as largeBinaryStreamMBS,size as integer)
dim i,t as integer
dim s as string
t=ticks
for i=1 to 100
s=l.read(size)
ProgressBar1.value=ProgressBar1.value+1
ProgressBar1.refresh
next
r.append ticks-t
End Sub
Sub testwrite(f as folderItem,m as string)
dim l as LargeBinaryStreamMBS
dim i,t as integer
l=f.CreateLargeBinaryStreamMBS("TEXT","ttxt")
if l<>nil then
if not l.CanWrite then
msgBox "Error creating file!"
return
end if
t=lenb(m)*100
i=l.Allocate(t,2) // Flags 2 for Contiguous Space
t=ticks
for i=1 to 100
l.write m
ProgressBar1.value=ProgressBar1.value+1
ProgressBar1.refresh
next
r.append ticks-t
l.close
else
msgBox "CreateLargeBinaryStream failed!"
end if
End Sub
Property Protected f As folderItem
Property Protected r(0) As integer
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Util Plugin.