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