|
|
|
|
@@ -1,192 +0,0 @@
|
|
|
|
|
// CellFS vs IO Performance Test
|
|
|
|
|
// Compares the speed of cellfs (miniz + fd) vs physfs-based io
|
|
|
|
|
|
|
|
|
|
var cellfs = use('cellfs')
|
|
|
|
|
var io = use('io')
|
|
|
|
|
var time = use('time')
|
|
|
|
|
var json = use('json')
|
|
|
|
|
var blob = use('blob')
|
|
|
|
|
var utf8 = use('utf8')
|
|
|
|
|
|
|
|
|
|
log.console("CellFS vs IO Performance Test")
|
|
|
|
|
log.console("=================================")
|
|
|
|
|
|
|
|
|
|
// Test file operations
|
|
|
|
|
var test_file = "test.txt"
|
|
|
|
|
var test_content = "Hello, World! This is a test file for performance comparison.\n"
|
|
|
|
|
|
|
|
|
|
// Create test data
|
|
|
|
|
log.console("Creating test file...")
|
|
|
|
|
io.writepath('.')
|
|
|
|
|
|
|
|
|
|
io.mount('.')
|
|
|
|
|
|
|
|
|
|
var io_paths = io.searchpath()
|
|
|
|
|
log.console(io_paths)
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < io_paths.length; i++) {
|
|
|
|
|
var path = io_paths[i]
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
cellfs.mount(path)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Some paths might not be mountable, skip them
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
io.slurpwrite(test_file, test_content)
|
|
|
|
|
|
|
|
|
|
// Verify both systems have the same search paths
|
|
|
|
|
log.console(`IO search paths: ${json.encode(io.searchpath())}`)
|
|
|
|
|
log.console(`CellFS search paths: ${json.encode(cellfs.searchpath())}`)
|
|
|
|
|
|
|
|
|
|
log.console("Testing read operations...")
|
|
|
|
|
|
|
|
|
|
// Test io.slurpbytes
|
|
|
|
|
var start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
|
var content = io.slurpbytes(test_file)
|
|
|
|
|
}
|
|
|
|
|
var io_time = time.number() - start_time
|
|
|
|
|
log.console(`IO slurpbytes (100 iterations): ${io_time}ms`)
|
|
|
|
|
|
|
|
|
|
// Test cellfs.slurpbytes
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
|
var content = cellfs.slurp(test_file)
|
|
|
|
|
}
|
|
|
|
|
var cellfs_time = time.number() - start_time
|
|
|
|
|
log.console(`CellFS slurpbytes (100 iterations): ${cellfs_time}ms`)
|
|
|
|
|
|
|
|
|
|
// Compare results
|
|
|
|
|
var speedup = io_time / cellfs_time
|
|
|
|
|
log.console(`CellFS is ${speedup.toFixed(2)}x ${speedup > 1 ? "faster" : "slower"} than IO for reading`)
|
|
|
|
|
|
|
|
|
|
// Test stat operations
|
|
|
|
|
log.console("\nTesting stat operations...")
|
|
|
|
|
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 1000; i++) {
|
|
|
|
|
var stats = io.stat(test_file)
|
|
|
|
|
}
|
|
|
|
|
io_time = time.number() - start_time
|
|
|
|
|
log.console(`IO stat (1000 iterations): ${io_time}ms`)
|
|
|
|
|
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 1000; i++) {
|
|
|
|
|
var stats = cellfs.stat(test_file)
|
|
|
|
|
}
|
|
|
|
|
cellfs_time = time.number() - start_time
|
|
|
|
|
log.console(`CellFS stat (1000 iterations): ${cellfs_time}ms`)
|
|
|
|
|
|
|
|
|
|
speedup = io_time / cellfs_time
|
|
|
|
|
log.console(`CellFS is ${speedup.toFixed(2)}x ${speedup > 1 ? "faster" : "slower"} than IO for stat`)
|
|
|
|
|
|
|
|
|
|
// Test exists operations
|
|
|
|
|
log.console("\nTesting exists operations...")
|
|
|
|
|
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 1000; i++) {
|
|
|
|
|
var exists = io.exists(test_file)
|
|
|
|
|
}
|
|
|
|
|
io_time = time.number() - start_time
|
|
|
|
|
log.console(`IO exists (1000 iterations): ${io_time}ms`)
|
|
|
|
|
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 1000; i++) {
|
|
|
|
|
var exists = cellfs.exists(test_file)
|
|
|
|
|
}
|
|
|
|
|
cellfs_time = time.number() - start_time
|
|
|
|
|
log.console(`CellFS exists (1000 iterations): ${cellfs_time}ms`)
|
|
|
|
|
|
|
|
|
|
speedup = io_time / cellfs_time
|
|
|
|
|
log.console(`CellFS is ${speedup.toFixed(2)}x ${speedup > 1 ? "faster" : "slower"} than IO for exists`)
|
|
|
|
|
|
|
|
|
|
// Test ZIP archive operations
|
|
|
|
|
log.console("\nTesting ZIP archive operations...")
|
|
|
|
|
|
|
|
|
|
// Create a test ZIP file using miniz
|
|
|
|
|
var miniz = use('miniz')
|
|
|
|
|
var zip_writer = miniz.write("test_archive.zip")
|
|
|
|
|
// Use io.slurpbytes to get content as ArrayBuffer for miniz
|
|
|
|
|
var content_bytes = io.slurpbytes(test_file)
|
|
|
|
|
zip_writer.add_file("test2.txt", content_bytes)
|
|
|
|
|
zip_writer = null // Close it
|
|
|
|
|
|
|
|
|
|
// Mount the ZIP with io
|
|
|
|
|
io.mount("test_archive.zip")
|
|
|
|
|
|
|
|
|
|
// Mount the ZIP with cellfs
|
|
|
|
|
cellfs.mount("test_archive.zip")
|
|
|
|
|
|
|
|
|
|
log.console("Testing ZIP file reading...")
|
|
|
|
|
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
|
var content = io.slurp("test2.txt")
|
|
|
|
|
}
|
|
|
|
|
io_time = time.number() - start_time
|
|
|
|
|
log.console(`IO ZIP read (100 iterations): ${io_time}ms`)
|
|
|
|
|
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
|
var content = cellfs.slurp("test2.txt")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cellfs_time = time.number() - start_time
|
|
|
|
|
log.console(`CellFS ZIP read (100 iterations): ${cellfs_time}ms`)
|
|
|
|
|
|
|
|
|
|
speedup = io_time / cellfs_time
|
|
|
|
|
log.console(`CellFS is ${speedup.toFixed(2)}x ${speedup > 1 ? "faster" : "slower"} than IO for ZIP reading`)
|
|
|
|
|
|
|
|
|
|
// Test large file operations
|
|
|
|
|
log.console("\nTesting large file operations...")
|
|
|
|
|
|
|
|
|
|
var large_file = "large_test.bin"
|
|
|
|
|
var size_mb = 10
|
|
|
|
|
var size_bits = size_mb * 1024 * 1024 * 8
|
|
|
|
|
log.console(`Creating ${size_mb}MB large file...`)
|
|
|
|
|
|
|
|
|
|
var blob = new blob(size_bits, function() { return Math.floor(Math.random() * (1 << 52)) })
|
|
|
|
|
stone(blob)
|
|
|
|
|
io.slurpwrite(large_file, blob)
|
|
|
|
|
|
|
|
|
|
log.console("Testing large file reading...")
|
|
|
|
|
|
|
|
|
|
// Test io.slurpbytes
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
|
var large_content = io.slurpbytes(large_file)
|
|
|
|
|
}
|
|
|
|
|
io_time = time.number() - start_time
|
|
|
|
|
log.console(`IO large file read (10 iterations): ${io_time}ms`)
|
|
|
|
|
|
|
|
|
|
start_time = time.number()
|
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
|
var large_content = cellfs.slurp(large_file)
|
|
|
|
|
}
|
|
|
|
|
cellfs_time = time.number() - start_time
|
|
|
|
|
log.console(`CellFS large file read (10 iterations): ${cellfs_time}ms`)
|
|
|
|
|
|
|
|
|
|
speedup = io_time / cellfs_time
|
|
|
|
|
log.console(`CellFS is ${speedup.toFixed(2)}x ${speedup > 1 ? "faster" : "slower"} than IO for large file reading`)
|
|
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
|
io.rm(test_file)
|
|
|
|
|
io.rm("test_archive.zip")
|
|
|
|
|
io.rm(large_file)
|
|
|
|
|
//io.unmount("/test_zip")
|
|
|
|
|
//cellfs.unmount("/test_zip")
|
|
|
|
|
|
|
|
|
|
// Unmount all the paths we mounted in cellfs
|
|
|
|
|
for (var path of io_paths) {
|
|
|
|
|
try {
|
|
|
|
|
cellfs.unmount(path)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Ignore unmount errors
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.console("\nTest completed!")
|
|
|
|
|
|
|
|
|
|
$_.stop()
|