From 2f3c3c0a1c2126f2c2537cd283f1e4785751f197 Mon Sep 17 00:00:00 2001 From: Mark Waddingham Date: Thu, 9 Mar 2017 13:58:31 +0000 Subject: [PATCH] [[ VarAccess ]] Add tests and benchmarks This patch adds some tests and some benchmarks covering variable access operations. --- .../lcs/control/variable.livecodescript | 317 ++++++++++++++++++ .../lcs/core/control/variable.livecodescript | 204 +++++++++++ 2 files changed, 521 insertions(+) create mode 100644 benchmarks/lcs/control/variable.livecodescript create mode 100644 tests/lcs/core/control/variable.livecodescript diff --git a/benchmarks/lcs/control/variable.livecodescript b/benchmarks/lcs/control/variable.livecodescript new file mode 100644 index 00000000000..e1bc668225c --- /dev/null +++ b/benchmarks/lcs/control/variable.livecodescript @@ -0,0 +1,317 @@ +script "ControlVariable" +/* +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 . */ + +constant kRepetitions = 100000 + +private command BenchmarkArrayAccess pOne, pTwo, pThree, pFour + BenchmarkStartTiming "Store[]" + repeat kRepetitions times + put empty into tVar + put 1 into tVar[pOne] + put 2 into tVar[pTwo] + put 3 into tVar[pThree] + put 4 into tVar[pFour] + end repeat + BenchmarkStopTiming + + BenchmarkStartTiming "Fetch[]" + repeat kRepetitions times + get tVar[pOne] + get tVar[pTwo] + get tVar[pThree] + get tVar[pFour] + end repeat + BenchmarkStopTiming + + BenchmarkStartTiming "Store[][]" + repeat kRepetitions times + put empty into tVar + put 1 into tVar[pOne][pTwo] + put 2 into tVar[pTwo][pThree] + put 3 into tVar[pThree][pFour] + put 4 into tVar[pFour][pOne] + end repeat + BenchmarkStopTiming + + BenchmarkStartTiming "Fetch[][]" + repeat kRepetitions times + get tVar[pOne][pTwo] + get tVar[pTwo][pThree] + get tVar[pThree][pFour] + get tVar[pFour][pOne] + end repeat + BenchmarkStopTiming +end BenchmarkArrayAccess + +on BenchmarkArrayNameKeys + BenchmarkArrayAccess "one", "two", "three", "four" +end BenchmarkArrayNameKeys + +on BenchmarkArrayIndexKeys + BenchmarkArrayAccess 1+0, 2+0, 3+0, 4+0 +end BenchmarkArrayIndexKeys + +on BenchmarkArrayStringKeys + BenchmarkArrayAccess "on" & "e", "tw" & "o", "thre" & "e", "fou" & "r" +end BenchmarkArrayStringKeys + +on BenchmarkVariableFetchLocal + local tVar + + local tName1, tName2, tName3, tName4 + put "one" into tName1 + put "two" into tName1 + put "three" into tName1 + put "four" into tName1 + + local tNumber1, tNumber2, tNumber3, tNumber4 + put 1 + 0 into tNumber1 + put 2 + 0 into tNumber2 + put 3 + 0 into tNumber3 + put 4 + 0 into tNumber4 + + local tString1, tString2, tString3, tString4 + put "on" & "e" into tString1 + put "tw" & "o" into tString2 + put "thre" & "e" into tString3 + put "fou" & "r" into tString4 + + local tSeq1_1, tSeq1_2, tSeq1_3, tSeq1_4 + put tName1 into tSeq1_1[1] + put tName2 into tSeq1_2[1] + put tName3 into tSeq1_3[1] + put tName4 into tSeq1_4[1] + + local tSeq2_1, tSeq2_2, tSeq2_3, tSeq2_4 + put tName1 into tSeq2_1[1] + put tName1 into tSeq2_1[2] + put tName2 into tSeq2_2[1] + put tName2 into tSeq2_2[2] + put tName3 into tSeq2_3[1] + put tName3 into tSeq2_3[2] + put tName4 into tSeq2_4[1] + put tName4 into tSeq2_4[2] + + put empty into tVar + put 100 into tVar + BenchmarkStartTiming "Get Base" + repeat kRepetitions times + get tVar + get tVar + get tVar + get tVar + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tName1] + put 100 into tVar[tName2] + put 100 into tVar[tName3] + put 100 into tVar[tName4] + BenchmarkStartTiming "Get Base[]" + repeat kRepetitions times + get tVar[tName1] + get tVar[tName2] + get tVar[tName3] + get tVar[tName4] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tNumber1] + put 100 into tVar[tNumber2] + put 100 into tVar[tNumber3] + put 100 into tVar[tNumber4] + BenchmarkStartTiming "Get Base[]" + repeat kRepetitions times + get tVar[tNumber1] + get tVar[tNumber2] + get tVar[tNumber3] + get tVar[tNumber4] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tString1] + put 100 into tVar[tString2] + put 100 into tVar[tString3] + put 100 into tVar[tString4] + BenchmarkStartTiming "Get Base[]" + repeat kRepetitions times + get tVar[tString1] + get tVar[tString2] + get tVar[tString3] + get tVar[tString4] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tSeq1_1] + put 100 into tVar[tSeq1_2] + put 100 into tVar[tSeq1_3] + put 100 into tVar[tSeq1_4] + BenchmarkStartTiming "Get Base[]" + repeat kRepetitions times + get tVar[tSeq1_1] + get tVar[tSeq1_2] + get tVar[tSeq1_3] + get tVar[tSeq1_4] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tName1][tName1] + put 100 into tVar[tName2][tName2] + put 100 into tVar[tName3][tName3] + put 100 into tVar[tName4][tName4] + BenchmarkStartTiming "Get Base[][]" + repeat kRepetitions times + get tVar[tName1][tName1] + get tVar[tName2][tName2] + get tVar[tName3][tName3] + get tVar[tName4][tName4] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tNumber1][tNumber1] + put 100 into tVar[tNumber2][tNumber2] + put 100 into tVar[tNumber3][tNumber3] + put 100 into tVar[tNumber4][tNumber4] + BenchmarkStartTiming "Get Base[][]" + repeat kRepetitions times + get tVar[tNumber1][tNumber1] + get tVar[tNumber2][tNumber2] + get tVar[tNumber3][tNumber3] + get tVar[tNumber4][tNumber4] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tString1][tString1] + put 100 into tVar[tString2][tString2] + put 100 into tVar[tString3][tString3] + put 100 into tVar[tString4][tString4] + BenchmarkStartTiming "Get Base[][]" + repeat kRepetitions times + get tVar[tString1][tString1] + get tVar[tString2][tString2] + get tVar[tString3][tString3] + get tVar[tString4][tString4] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tSeq2_1] + put 100 into tVar[tSeq2_2] + put 100 into tVar[tSeq2_3] + put 100 into tVar[tSeq2_4] + BenchmarkStartTiming "Get Base[]" + repeat kRepetitions times + get tVar[tSeq2_1] + get tVar[tSeq2_2] + get tVar[tSeq2_3] + get tVar[tSeq2_4] + end repeat + BenchmarkStopTiming +end BenchmarkVariableFetchLocal + +on BenchmarkVariableStoreLocal + local tVar, tName, tNumber, tString, tSeq1, tSeq2 + put "one" into tName + put 1 + 0 into tNumber + put "on" & "e" into tString + put tName into tSeq1[1] + put tName into tSeq2[1] + put tName into tSeq2[2] + + put empty into tVar + put 100 into tVar + BenchmarkStartTiming "Replace Into Base" + repeat kRepetitions times + put 100 into tVar + put 100 into tVar + put 100 into tVar + put 100 into tVar + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tName] + BenchmarkStartTiming "Replace Into Base[]" + repeat kRepetitions times + put 100 into tVar[tName] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tNumber] + BenchmarkStartTiming "Replace Into Base[]" + repeat kRepetitions times + put 100 into tVar[tNumber] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tString] + BenchmarkStartTiming "Replace Into Base[]" + repeat kRepetitions times + put 100 into tVar[tString] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tSeq1] + BenchmarkStartTiming "Replace Into Base[]" + repeat kRepetitions times + put 100 into tVar[tSeq1] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tName][tName] + BenchmarkStartTiming "Replace Into Base[][]" + repeat kRepetitions times + put 100 into tVar[tName][tName] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tNumber][tNumber] + BenchmarkStartTiming "Replace Into Base[][]" + repeat kRepetitions times + put 100 into tVar[tNumber][tNumber] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tString][tString] + BenchmarkStartTiming "Replace Into Base[][]" + repeat kRepetitions times + put 100 into tVar[tString][tString] + end repeat + BenchmarkStopTiming + + put empty into tVar + put 100 into tVar[tSeq2] + BenchmarkStartTiming "Replace Into Base[]" + repeat kRepetitions times + put 100 into tVar[tSeq2] + end repeat + BenchmarkStopTiming +end BenchmarkVariableStoreLocal diff --git a/tests/lcs/core/control/variable.livecodescript b/tests/lcs/core/control/variable.livecodescript new file mode 100644 index 00000000000..7518ae7f89e --- /dev/null +++ b/tests/lcs/core/control/variable.livecodescript @@ -0,0 +1,204 @@ +script "CoreControlVariable" +/* +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 . */ + +on TestFetchLocal + local tVar, tIndex + + put empty into tVar + put 100 into tVar + TestAssert "local direct access", tVar is 100 + + put empty into tVar + put 100 into tVar["one"] + TestAssert "local indirect name - depth 1", tVar["one"] is 100 + + put empty into tVar + put 100 into tVar["one"]["one"] + TestAssert "local indirect name - depth 2", tVar["one"]["one"] is 100 + + put empty into tVar + put 100 into tVar[1+0] + TestAssert "local indirect number - depth 1", tVar[1+0] is 100 + + put empty into tVar + put 100 into tVar[1+0][1+0] + TestAssert "local indirect number - depth 2", tVar[1+0][1+0] is 100 + + put empty into tIndex + put 1+0 into tIndex[1+0] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "local indirect number array - depth 1", tVar[tIndex] is 100 + + put empty into tIndex + put 1+0 into tIndex[1+0] + put 1+0 into tIndex[2+0] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "local indirect number array - depth 2", tVar[tIndex] is 100 + + put empty into tIndex + put "one" into tIndex[1+0] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "local indirect name array - depth 1", tVar[tIndex] is 100 + + put empty into tIndex + put "one" into tIndex[1+0] + put "one" into tIndex[2+0] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "local indirect name array - depth 2", tVar[tIndex] is 100 + + put empty into tIndex + put 1+0 into tIndex[1] + put "one" into tIndex[2] + put empty into tVar + put 100 into tVar[1][tIndex]["one"] + TestAssert "local indirect mixed - depth 4", tVar[1+0][tIndex]["one"] is 100 +end TestFetchLocal + +private command DoTestFetchParam tVar + local tIndex + + put empty into tVar + put 100 into tVar + TestAssert "param direct access", tVar is 100 + + put empty into tVar + put 100 into tVar["one"] + TestAssert "param indirect name - depth 1", tVar["one"] is 100 + + put empty into tVar + put 100 into tVar["one"]["one"] + TestAssert "param indirect name - depth 2", tVar["one"]["one"] is 100 + + put empty into tVar + put 100 into tVar[1] + TestAssert "param indirect number - depth 1", tVar[1] is 100 + + put empty into tVar + put 100 into tVar[1][1] + TestAssert "param indirect number - depth 2", tVar[1][1] is 100 + + put empty into tIndex + put 1 into tIndex[1] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect number array - depth 1", tVar[tIndex] is 100 + + put empty into tIndex + put 1 into tIndex[1] + put 1 into tIndex[2] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect number array - depth 2", tVar[tIndex] is 100 + + put empty into tIndex + put "one" into tIndex[1] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect name array - depth 1", tVar[tIndex] is 100 + + put empty into tIndex + put "one" into tIndex[1] + put "one" into tIndex[2] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect name array - depth 2", tVar[tIndex] is 100 + + put empty into tIndex + put "1" into tIndex[1] + put "one" into tIndex[2] + put empty into tVar + put 100 into tVar[1][tIndex]["one"] + TestAssert "param indirect mixed - depth 4", tVar[1][tIndex]["one"] is 100 +end DoTestFetchParam + +on TestFetchParam + local tParam + DoTestFetchParam tParam +end TestFetchParam + +private command DoTestFetchRefParam @tVar + local tIndex + + put empty into tVar + put 100 into tVar + TestAssert "param direct access", tVar is 100 + + put empty into tVar + put 100 into tVar["one"] + TestAssert "param indirect name - depth 1", tVar["one"] is 100 + + put empty into tVar + put 100 into tVar["one"]["one"] + TestAssert "param indirect name - depth 2", tVar["one"]["one"] is 100 + + put empty into tVar + put 100 into tVar[1] + TestAssert "param indirect number - depth 1", tVar[1] is 100 + + put empty into tVar + put 100 into tVar[1][1] + TestAssert "param indirect number - depth 2", tVar[1][1] is 100 + + put empty into tIndex + put 1 into tIndex[1] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect number array - depth 1", tVar[tIndex] is 100 + + put empty into tIndex + put 1 into tIndex[1] + put 1 into tIndex[2] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect number array - depth 2", tVar[tIndex] is 100 + + put empty into tIndex + put "one" into tIndex[1] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect name array - depth 1", tVar[tIndex] is 100 + + put empty into tIndex + put "one" into tIndex[1] + put "one" into tIndex[2] + put empty into tVar + put 100 into tVar[tIndex] + TestAssert "param indirect name array - depth 2", tVar[tIndex] is 100 + + put empty into tIndex + put "1" into tIndex[1] + put "one" into tIndex[2] + put empty into tVar + put 100 into tVar[1][tIndex]["one"] + TestAssert "param indirect mixed - depth 4", tVar[1][tIndex]["one"] is 100 +end DoTestFetchRefParam + +on TestFetchRefParam + local tParam + DoTestFetchRefParam tParam +end TestFetchRefParam + +on TestFetchScriptLocal +end TestFetchScriptLocal + +on TestFetchGlobal +end TestFetchGlobal