This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy patharray.livecodescript
More file actions
208 lines (180 loc) · 5.89 KB
/
Copy patharray.livecodescript
File metadata and controls
208 lines (180 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
script "ControlArray"
/*
Copyright (C) 2017 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
on BenchmarkArrayBug17434
local tMax
put 100 into tMax
local sA
BenchmarkStartTiming "Bug 17434 - 3-dim matrix"
repeat with i = 1 to tMax
repeat with j = 1 to tMax
repeat with k = 1 to tMax
put "bob,carol,ted,alice" into sA[i][j][k]
end repeat
end repeat
end repeat
BenchmarkStopTiming
end BenchmarkArrayBug17434
on BenchmarkArrayWordCount
/* Generate 10Mb of text from a public domain book */
local tContent
BenchmarkLoadNativeTextFile "the_adventures_of_sherlock_holmes.txt"
repeat while (the number of chars in tContent) < 10 * 1024 * 1024
put the result after tContent
end repeat
local tWordCount, tKeyWords, tResult
BenchmarkStartTiming "WordCount - iterate"
repeat for each word tWord in tContent
end repeat
BenchmarkStopTiming
put empty into tWordCount
BenchmarkStartTiming "WordCount - count"
repeat for each word tWord in tContent
add 1 to tWordCount[tWord]
end repeat
BenchmarkStopTiming
BenchmarkStartTiming "WordCount - keys then sort then combine"
put the keys of tWordCount into tKeyWords
sort tKeyWords
repeat for each line tWord in tKeyWords
put tWord & tab & tWordCount[tWord] & return after tResult
end repeat
BenchmarkStopTiming
put empty into tResult
BenchmarkStartTiming "WordCount - combine then sort"
repeat for each line tWord in tKeyWords
put tWord & tab & tWordCount[tWord] & return after tResult
end repeat
set the itemDelimiter to tab
sort tResult by item 1 of each
BenchmarkStopTiming
end BenchmarkArrayWordCount
on BenchmarkArrayFilterRecords
local tRecords, tFilteredRecords
put _BenchmarkArrayFilterGetRecords() into tRecords
local tWantedColumns
put "First name,Test1,Grade" into tWantedColumns
BenchmarkStartTiming "FilterRecords - stringlist"
repeat 100000 times
get _BenchmarkArrayFilterRecords(tRecords, tWantedColumns)
end repeat
BenchmarkStopTiming
split tWantedColumns by comma as set
BenchmarkStartTiming "FilterRecords - set"
repeat 100000 times
get _BenchmarkArrayFilterRecordsSet(tRecords, tWantedColumns)
end repeat
BenchmarkStopTiming
end BenchmarkArrayFilterRecords
private function _BenchmarkArrayFilterRecords pRecords, pColumnNames
local tFilteredRecords, tFilteredRecord
repeat for each element tRecord in pRecords
repeat for each item tColumnName in pColumnNames
put tRecord[tColumnName] into tFilteredRecord[tColumnName]
end repeat
put tFilteredRecord into \
tFilteredRecords[the number of elements in tFilteredRecords + 1]
end repeat
return tFilteredRecords
end _BenchmarkArrayFilterRecords
private function _BenchmarkArrayFilterRecordsSet pRecords, pColumnNameSet
local tFilteredRecords, tFilteredRecord
repeat for each element tRecord in pRecords
repeat for each key tColumnName in pColumnNameSet
put tRecord[tColumnName] into tFilteredRecord[tColumnName]
end repeat
put tFilteredRecord into \
tFilteredRecords[the number of elements in tFilteredRecords + 1]
end repeat
return tFilteredRecords
end _BenchmarkArrayFilterRecordsSet
private function _BenchmarkArrayFilterGetRecords
local tData
BenchmarkLoadNativeTextFile "example_tsv_records.txt"
put the result into tData
local tColumnNames
put line 1 of tData into tColumnNames
split tColumnNames by tab
local tRecords, tRecordIndex
put 1 into tRecordIndex
repeat for each line tRow in line 2 to -1 of tData
split tRow by tab
repeat with tColumnIndex = 1 to the number of elements in tRow
put tRow[tColumnIndex] into \
tRecords[tRecordIndex][tColumnNames[tColumnIndex]]
end repeat
add 1 to tRecordIndex
end repeat
return tRecords
end _BenchmarkArrayFilterGetRecords
on BenchmarkCKSqrtLoop
BenchmarkStartTiming "CK Sqrt Loop"
local n
repeat with i = 1 to 1000000
add sqrt(i) to n
end repeat
BenchmarkStopTiming
end BenchmarkCKSqrtLoop
on BenchmarkCKAppendFromArray
BenchmarkStartTiming "CK Big List (prepare)"
local tList, tCount
put 9 into tCount
put "apple,banana,carrot,dairy,egg," into tList
repeat tCount - 1 times
put tList after tList
end repeat
BenchmarkStopTiming
local tMod
put the number of items in tList into tMod
local tOutput
BenchmarkStartTiming "CK Big List (non-array)"
repeat with i=0 to 500000-1
put item i*7 mod tMod + 1 of tList & space after tOutput
end repeat
BenchmarkStopTiming
BenchmarkStartTiming "CK Big List (split)"
split tList by comma
BenchmarkStopTiming
BenchmarkStartTiming "CK Big List (array)"
repeat with i=0 to 500000-1
put tList[i*7 mod tMod + 1] & space after tOutput
end repeat
BenchmarkStopTiming
end BenchmarkCKAppendFromArray
on BenchmarkCKLargeText
local x, y, n, i
BenchmarkStartTiming "CK Large Text - 3 (non-cs prepare)"
set the caseSensitive to false
put "fab" into x
put "fzb" into y
put "abcdefghij " into n
repeat with i = 1 to 24
put n & codeunit i mod 10 + 1 of n after n
end repeat
BenchmarkStopTiming
BenchmarkStartTiming "CK Large Text - 3 (non-cs run)"
replace x with y in n
BenchmarkStopTiming
BenchmarkStartTiming "CK Large Text - 3 (cs prepare)"
set the caseSensitive to true
put "fab" into x
put "fzb" into y
put "abcdefghij " into n
repeat with i = 1 to 24
put n & codeunit i mod 10 + 1 of n after n
end repeat
BenchmarkStopTiming
BenchmarkStartTiming "CK Large Text - 3 (cs run)"
replace x with y in n
BenchmarkStopTiming
end BenchmarkCKLargeText