Platforms to show: All Mac Windows Linux Cross-Platform
/Util/FileList/FileList Benchmark
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/FileList/FileList Benchmark
This example is the version from Tue, 4th Feb 2019.
Project "FileList Benchmark.xojo_binary_project"
Class MainWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
dim dir as folderitem = SpecialFolder.System
TimeFolderMBS dir
TimeFolderXojo dir
End EventHandler
End Control
EventHandler Sub Open()
StaticText1.text="Processing..."
me.show
'MsgBox "Please wait. Benchmark can take a few seconds..."
dim dir as folderitem = MakeFolder
TimeFolderMBS dir
TimeFolderXojo dir
End EventHandler
Function MakeFolder() As FolderItem
// create a test folder
dim dir as folderitem = SpecialFolder.Desktop.Child("FileList Benchmark data")
dir.CreateAsFolder
dim t as double = Microseconds
if dir.Count = 10000 then return dir // already there
for i as integer = 0 to 9999
dim name as string = Format(i,"00000")
dim file as FolderItem = dir.Child(name + ".txt")
// writefile is faster
if not file.WriteFileMBS(name) then
break // error?
end if
'dim t as TextOutputStream = file.CreateTextFile
't.Write name
't.Close
next
t = Microseconds - t
StaticText1.text="Created 10000 files: "+str(t,"0")+" microseconds."
return dir
End Function
Sub TimeFolderMBS(dir as FolderItem)
dim t as double = Microseconds
Count = 0
dim f as new FileListMBS(dir)
dim size as Int64 = WalkFolderMBS(f)
t = Microseconds - t
StaticText2.text=str(Count)+" items found via plugin: "+str(t/1000.0,"0")+" milliseconds and "+str(size/1000000.0, "0.0")+" MB"
End Sub
Sub TimeFolderXojo(dir as FolderItem)
dim t as double = microseconds
Count = 0
dim size as Int64 = WalkFolderXojo(dir)
t = microseconds - t
StaticText3.text=str(Count)+" items found via pure Xojo: "+str(t/1000.0,"0")+" milliseconds and "+str(size/1000000.0, "0.0")+" MB"
End Sub
Function WalkFolderMBS(f as FileListMBS) As Int64
dim size as Int64 = 0
dim c as integer = f.Count-1
for i as integer = 0 to c
dim Name as string = f.Name(i) // read all the names
if f.Directory(i) then
dim g as new FileListMBS(f, i)
size = size + WalkFolderMBS(g)
else
// file
Count = Count + 1
size = size + f.LogicalDataLength(i)
end if
next
return size
End Function
Function WalkFolderXojo(dir as FolderItem) As Int64
dim size as Int64 = 0
dim c as integer = dir.Count
for i as integer = 1 to c
dim file as FolderItem = dir.TrueItem(i)
dim name as string = file.name // read all the names
if file.Directory then
size = size + WalkFolderXojo(file)
else
Count = Count + 1
size = size + file.Length
end if
next
return size
End Function
Property Count 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.