Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BaselineOfBasicTools/BaselineOfBasicTools.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ BaselineOfBasicTools >> baseline: spec [
baseline: 'Debugging' with: [ spec loads: 'Core' from: repository ];
baseline: 'UnifiedFFI' with: [ spec repository: repository ];
baseline: 'ThreadedFFI' with: [ spec repository: repository ];
baseline: 'NewFiles' with: [ spec repository: repository ];
baseline: 'UIInfrastructure' with: [ spec repository: repository ];
baseline: 'UI' with: [ spec repository: repository ];
baseline: 'Reflectivity' with: [ spec repository: repository ];
Expand Down
19 changes: 19 additions & 0 deletions src/BaselineOfNewFiles/BaselineOfNewFiles.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Class {
#name : 'BaselineOfNewFiles',
#superclass : 'BaselineOf',
#category : 'BaselineOfNewFiles',
#package : 'BaselineOfNewFiles'
}

{ #category : 'baselines' }
BaselineOfNewFiles >> baseline: spec [
<baseline>
spec for: #'common' do: [
spec
package: 'NewFiles';
package: 'NewFiles-Tests'.
spec
group: 'Core' with: #('NewFiles');
group: 'Tests' with: #('NewFiles-Tests');
group: 'default' with: #('Core' 'Tests') ]
]
1 change: 1 addition & 0 deletions src/BaselineOfNewFiles/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'BaselineOfNewFiles' }
4 changes: 3 additions & 1 deletion src/FileSystem-Disk/DiskStore.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ DiskStore >> gidOf: aPath [

{ #category : 'accessing' }
DiskStore >> handleClass [
^ FileHandle
^ (Smalltalk globals at: #FileAPI ifAbsent: [ nil ])
ifNil: [ FileHandle ]
ifNotNil: [ :fileAPI | fileAPI currentFileClass ]
]

{ #category : 'comparing' }
Expand Down
165 changes: 165 additions & 0 deletions src/NewFiles-Tests/FileAPIBenchmarks.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
"
I hold different benchmarks for testing the old file plugin vs the new file plugin.
"
Class {
#name : 'FileAPIBenchmarks',
#superclass : 'Object',
#instVars : [
'fileAPI',
'file',
'random',
'randomData',
'smallRandomData',
'randomOffsets'
],
#classVars : [
'RandomDataSize',
'ReadBufferCount',
'SmallRandomDataSize',
'SmallReadBufferCount',
'SmallWriteBufferCount',
'WriteBufferCount'
],
#category : 'NewFiles-Tests',
#package : 'NewFiles-Tests'
}

{ #category : 'class initialization' }
FileAPIBenchmarks class >> initialize [
RandomDataSize := 1000000.
SmallRandomDataSize := 2048.

SmallWriteBufferCount := 100000.
SmallReadBufferCount := SmallWriteBufferCount.

WriteBufferCount := 1000.
ReadBufferCount := WriteBufferCount.

]

{ #category : 'as yet unclassified' }
FileAPIBenchmarks class >> runWithFileAPI: aFileAPI [
^ self new fileAPI: aFileAPI; run; yourself
]

{ #category : 'accessing' }
FileAPIBenchmarks >> fileAPI [

^ fileAPI
]

{ #category : 'accessing' }
FileAPIBenchmarks >> fileAPI: anObject [

fileAPI := anObject
]

{ #category : 'as yet unclassified' }
FileAPIBenchmarks >> generateRandomData [
random := Random seed: 42.

randomData := ByteArray new: RandomDataSize.
1 to: RandomDataSize do: [ :index |
randomData at: index put: (random nextInteger: 255)
].

smallRandomData := ByteArray new: SmallRandomDataSize.
1 to: SmallRandomDataSize do: [ :index |
smallRandomData at: index put: (random nextInteger: 255)
].

randomOffsets := IntegerArray new: SmallWriteBufferCount.
1 to: SmallWriteBufferCount do: [ :i |
randomOffsets at: i put: (random nextInteger: RandomDataSize // 10)
].
]

{ #category : 'as yet unclassified' }
FileAPIBenchmarks >> measure: aBlock withSampleCount: sampleCount title: title [
| samples sampleIOSize sampleTime sampleSpeed average stdev |
samples := Array new: sampleCount.
1 to: sampleCount do: [ :sampleIndex |
sampleIOSize := 0.
sampleTime := [
sampleIOSize := aBlock value: sampleIndex
] microsecondsToRun * 1e-6.
sampleSpeed := sampleIOSize asFloat / (sampleTime max: 1e-6) * 1e-6.

samples at: sampleIndex put: sampleSpeed
].

average := samples average.
stdev := samples stdev.
Transcript show: title;
show: ' '; show: sampleCount; show: ' samples';
show: ' speed (MB/s): '; show: average; show: ' +- '; show: stdev; cr.
]

{ #category : 'writing' }
FileAPIBenchmarks >> readData [
| readBuffer |
readBuffer := ByteArray new: randomData size.
file position: 0.
self measure: [ :sampleIndex |
| readCount |
readCount := file readInto: readBuffer.
self assert: readCount >= 0.
readCount
] withSampleCount: ReadBufferCount title: 'readData'

]

{ #category : 'running' }
FileAPIBenchmarks >> run [
| randomDatasetGenerationTime |
file := fileAPI openCreateAlways: fileAPI apiName , '-Benchmarks.bin'.
[
Transcript show: fileAPI apiName; show: ' Benchmarks'; cr.

randomDatasetGenerationTime := [ self generateRandomData ] timeToRun asMicroseconds * 0.001.
Transcript show: 'RandomDatasetGenerationTime '; show: randomDatasetGenerationTime asString; show: ' ms'; cr.

self writeDataAtRandomOffsets.
self writeSmallData.
self writeData.
self readData.
] ensure: [
file close
]

]

{ #category : 'writing' }
FileAPIBenchmarks >> writeData [
file position: 0.
self measure: [ :sampleIndex |
| writeCount |
writeCount := file writeFrom: randomData.
self assert: writeCount >= 0.
writeCount
] withSampleCount: WriteBufferCount title: 'writeData'
]

{ #category : 'writing' }
FileAPIBenchmarks >> writeDataAtRandomOffsets [
self measure: [ :sampleIndex |
| writeCount |
file position: (randomOffsets at: sampleIndex).
writeCount := file writeFrom: smallRandomData.
self assert: writeCount >= 0.
writeCount
] withSampleCount: randomOffsets size title: 'writeDataAtRandomOffsets'.

]

{ #category : 'writing' }
FileAPIBenchmarks >> writeSmallData [
file position: 0.
self measure: [ :sampleIndex |
| writeCount |
file position: (randomOffsets at: sampleIndex).
writeCount := file writeFrom: smallRandomData.
self assert: writeCount >= 0.
writeCount
] withSampleCount: SmallWriteBufferCount title: 'writeSmallData'.
]
140 changes: 140 additions & 0 deletions src/NewFiles-Tests/FileAPITest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
Class {
#name : 'FileAPITest',
#superclass : 'TestCase',
#category : 'NewFiles-Tests',
#package : 'NewFiles-Tests'
}

{ #category : 'tests' }
FileAPITest >> testHelloWorld [
| path text file buffer decodedText |
path := 'test.txt'.
text := 'Hello World'.

file := FileAPI openCreateAlways: path.
file writeFrom: text utf8Encoded.
file close.

file := FileAPI openReadOnly: path.
buffer := ByteArray new: file size.
file readInto: buffer.
file close.

decodedText := buffer utf8Decoded.
self assert: decodedText equals: text.

FileAPI deleteFile: path.
]

{ #category : 'tests' }
FileAPITest >> testHelloWorld2 [
| path text file buffer decodedText |
path := 'test.txt'.
text := 'Hello World'.

file := FileAPI openCreateAlways: path.
file writeFrom: text utf8Encoded.

buffer := ByteArray new: file size.
file position: 0.
file readInto: buffer.
file close.

decodedText := buffer utf8Decoded.
self assert: decodedText equals: text.

FileAPI deleteFile: path.
]

{ #category : 'tests' }
FileAPITest >> testHelloWorldAbsolutePath [
| path text file buffer decodedText |
path := 'test.txt' asFileReference asAbsolute fullName.
text := 'Hello World'.

file := FileAPI openCreateAlways: path.
file writeFrom: text utf8Encoded.
file close.

file := FileAPI openReadOnly: path.
buffer := ByteArray new: file size.
file readInto: buffer.
file close.

decodedText := buffer utf8Decoded.
self assert: decodedText equals: text.

FileAPI deleteFile: path.
]

{ #category : 'tests' }
FileAPITest >> testHelloWorldAtFileOffset [
| path text file buffer decodedText |
path := 'test.txt'.
text := 'Hello World'.

file := FileAPI openCreateAlways: path.
file writeFrom: text utf8Encoded at: 0.
file close.

file := FileAPI openReadOnly: path.
buffer := ByteArray new: file size.
file readInto: buffer at: 0.
file close.

decodedText := buffer utf8Decoded.
self assert: decodedText equals: text.

FileAPI deleteFile: path.
]

{ #category : 'tests' }
FileAPITest >> testHelloWorldAtFileOffset2 [
| path text file buffer decodedText |
path := 'test.txt'.
text := 'Hello World'.

file := FileAPI openCreateAlways: path.
file writeFrom: text utf8Encoded at: 0.

buffer := ByteArray new: file size.
file readInto: buffer at: 0.

file close.

decodedText := buffer utf8Decoded.
self assert: decodedText equals: text.

FileAPI deleteFile: path.
]

{ #category : 'tests' }
FileAPITest >> testHelloWorldContents [
| path text file buffer decodedText |
path := 'test.txt'.
text := 'Hello World'.

file := FileAPI openCreateAlways: path.
file writeFrom: text utf8Encoded.

buffer := file contents.
file close.

decodedText := buffer utf8Decoded.
self assert: decodedText equals: text.

FileAPI deleteFile: path.
]

{ #category : 'tests' }
FileAPITest >> testTruncate [
| path file |
path := 'test.bin'.

file := FileAPI openCreateAlways: path.
file truncateToSize: 4096.
self assert: file size equals: 4096.
file close.

FileAPI deleteFile: path.
]
Loading