1
- import Automerge
2
1
import CollectionsBenchmark
3
2
import Foundation
3
+ import Automerge
4
+ import Loro
4
5
5
6
// NOTE(heckj): collections-benchmark implementations can be a bit hard to understand
6
7
// from the opaque inputs and structure of the code.
@@ -76,6 +77,23 @@ benchmark.addSimple(
76
77
blackHole ( doc)
77
78
}
78
79
80
+ benchmark. addSimple (
81
+ title: " Text - append (Loro) " ,
82
+ input: [ String ] . self
83
+ ) { input in
84
+ let doc = LoroDoc ( )
85
+ let text = doc. getText ( id: " text " )
86
+
87
+ var stringLength = text. lenUnicode ( )
88
+ for strChar in input {
89
+ _ = try ! text. splice ( pos: stringLength, len: 0 , s: strChar)
90
+ stringLength = text. lenUnicode ( )
91
+ }
92
+ // precondition(stringLength == input.count) // NOT VALID - difference in UTF-8 codepoints and how strings represent
93
+ // lengths
94
+ blackHole ( doc)
95
+ }
96
+
79
97
benchmark. addSimple (
80
98
title: " Text - append and read " ,
81
99
input: [ String ] . self
@@ -94,6 +112,25 @@ benchmark.addSimple(
94
112
blackHole ( resultingString)
95
113
}
96
114
115
+ benchmark. addSimple (
116
+ title: " Text - append and read (Loro) " ,
117
+ input: [ String ] . self
118
+ ) { input in
119
+ let doc = LoroDoc ( )
120
+ let text = doc. getText ( id: " text " )
121
+
122
+ var stringLength = text. lenUnicode ( )
123
+ for strChar in input {
124
+ _ = try ! text. splice ( pos: stringLength, len: 0 , s: strChar)
125
+ stringLength = text. lenUnicode ( )
126
+ }
127
+
128
+ let resultingString = text. toString ( )
129
+ // precondition(stringLength == input.count) // NOT VALID - difference in UTF-8 codepoints and how strings represent
130
+ // lengths
131
+ blackHole ( resultingString)
132
+ }
133
+
97
134
benchmark. addSimple (
98
135
title: " List - Integer append " ,
99
136
input: [ Int ] . self
@@ -110,6 +147,22 @@ benchmark.addSimple(
110
147
blackHole ( doc)
111
148
}
112
149
150
+ benchmark. addSimple (
151
+ title: " List - Integer append (Loro) " ,
152
+ input: [ Int ] . self
153
+ ) { integerInput in
154
+ let doc = LoroDoc ( )
155
+ let numList = doc. getList ( id: " list " )
156
+
157
+ for intValue in integerInput {
158
+ let listLength = numList. len ( )
159
+ try ! numList. insert ( pos: listLength, v: intValue)
160
+ }
161
+ // precondition(stringLength == input.count) // NOT VALID - difference in UTF-8 codepoints and how strings represent
162
+ // lengths
163
+ blackHole ( doc)
164
+ }
165
+
113
166
benchmark. addSimple (
114
167
title: " Map - Integer append " ,
115
168
input: [ Int ] . self
@@ -125,5 +178,20 @@ benchmark.addSimple(
125
178
blackHole ( doc)
126
179
}
127
180
181
+ benchmark. addSimple (
182
+ title: " Map - Integer append (Loro) " ,
183
+ input: [ Int ] . self
184
+ ) { integerInput in
185
+ let doc = LoroDoc ( )
186
+ let numberMap = doc. getMap ( id: " map " )
187
+
188
+ for intValue in integerInput {
189
+ try ! numberMap. insert ( key: String ( intValue) , v: intValue)
190
+ }
191
+ // precondition(stringLength == input.count) // NOT VALID - difference in UTF-8 codepoints and how strings represent
192
+ // lengths
193
+ blackHole ( doc)
194
+ }
195
+
128
196
// Execute the benchmark tool with the above definitions.
129
197
benchmark. main ( )
0 commit comments