Difference between revisions of "TI-BASIC:Better Code Timings"
lirtosiast (talk | contribs) |
lirtosiast (talk | contribs) |
||
Line 1: | Line 1: | ||
= Instructions = | = Instructions = | ||
− | First, write the name and model of your calculator in the table below, then use this code | + | First, write the name and model of your calculator in the table below, then use this code to measure your loop overhead (without an empty line). |
Add the number of iterations you used to the "iterations" column, and [time taken]/[iterations] to the "average" column. Then subtract your loop overhead from the result and list it in the "time" column. | Add the number of iterations you used to the "iterations" column, and [time taken]/[iterations] to the "average" column. Then subtract your loop overhead from the result and list it in the "time" column. | ||
Line 34: | Line 34: | ||
|} | |} | ||
− | == List | + | == List Commands == |
Unless specified, all list/matrix elements are equal to 1, and all dimensions are equal to 20. | Unless specified, all list/matrix elements are equal to 1, and all dimensions are equal to 20. | ||
Line 108: | Line 108: | ||
|} | |} | ||
+ | == Matrix Commands== | ||
When using matrix commands, remember that matrix multiplication is O(n^3). It's probably slower than other solutions for large matrices. | When using matrix commands, remember that matrix multiplication is O(n^3). It's probably slower than other solutions for large matrices. |
Revision as of 01:45, 30 March 2016
Instructions
First, write the name and model of your calculator in the table below, then use this code to measure your loop overhead (without an empty line).
Add the number of iterations you used to the "iterations" column, and [time taken]/[iterations] to the "average" column. Then subtract your loop overhead from the result and list it in the "time" column.
FnOff PlotsOff 0→Xmin 94→Xmax -62→Ymin 0→Ymax DispGraph //if it is a graphing command startTmr→θ Repeat checkTmr(θ End For(𝑛,1,[iterations]) //sequence variable 𝑛; note the closing parenthesis. //test code here End checkTmr(θ+1
Contents
Math Commands
Unless specified, all variables are equal to 1.
Command | Iterations | Average (ms) | Loop overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
N=I% and FV=PV | 1000 | 4.? | 0.6 | ~4 | 2.55MP/lirtosiast |
N+FV[i]=I%+PV[i] | 1000 | 7.? | 0.6 | ~7 | 2.55MP/lirtosiast |
List Commands
Unless specified, all list/matrix elements are equal to 1, and all dimensions are equal to 20.
Command | Iterations | Average (ms) | Overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
L1 | 1000 | 2.? | 0.6 | ~2 | 2.55MP/lirtosiast |
not(L1 | 1000 | 9.? | 0.6 | ~9 | 2.55MP/lirtosiast |
L1+0 | 1000 | 20 | 0.6 | ~20 | 2.55MP/lirtosiast |
cumSum(L1 | 1000 | 19 | 0.6 | ~19 | 2.55MP/lirtosiast |
DeltaList(L1 | 1000 | 26 | 0.6 | ~26 | 2.55MP/lirtosiast |
augment(L1,L1 | 10000 | 9.4 | 0.6 | 8.8 | 2.55MP/lirtosiast |
augment(L1,{1 | 10000 | 7.7 | 0.6 | 7.1 | 2.55MP/lirtosiast |
augment({1},L1 //dim=20 | 10000 | 7.7 | 0.6 | 7.1 | 2.55MP/lirtosiast |
augment({1},{1 | 10000 | 6.0 | 0.6 | 5.4 | 2.55MP/lirtosiast |
DeltaList(L1 //dim=20 | 1000 | 26 | 0.6 | ~26 | 2.55MP/lirtosiast |
Fill(1,L1 //dim=20 | 10000 | 3.9 | 0.6 | 3.3 | 2.55MP/lirtosiast |
Below we can see that using the same variable for the seq( variable as the For( variable doesn't slow anything down. The value of the variable before seq( was called is restored in a constant amount of time.
Command | Iterations | Average (ms) | Overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
seq(1,n,1,20 //loop var n | 1000 | 70 | 0.6 | 70 | 2.55MP/lirtosiast |
seq(1,n,1,20 //loop var X | 1000 | 71 | 1.1 | 70 | 2.55MP/lirtosiast |
seq(1,X,1,20 //loop var n | 1000 | 82 | 0.6 | 82 | 2.55MP/lirtosiast |
seq(1,X,1,20 //loop var X | 1000 | 83 | 1.1 | 82 | 2.55MP/lirtosiast |
seq( has a large overhead (about 3.5 ms per element), but the penalty doesn't increase by much when the expression inside the seq( is large. Vectorized list operations outside the seq( are only marginally faster than operations inside the seq(.
Command | Iterations | Average (ms) | Overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
seq(1+1,n,1,20 | 1000 | 92 | 0.6 | 92 | 2.55MP/lirtosiast |
1+seq(1,n,1,20 | 1000 | 92 | 0.6 | 92 | 2.55MP/lirtosiast |
seq(not(1),n,1,20 | 1000 | 79 | 0.6 | 79 | 2.55MP/lirtosiast |
not(seq(1,n,1,20 | 1000 | 76 | 0.6 | 76 | 2.55MP/lirtosiast |
binomcdf(N-1,0 is often used to construct a list of a certain length N, but binompdf( can be slightly faster. The difference is about equal to the time for a call to cumSum(. When called with a second argument that is not 0 or 1, binompdf( slows down dramatically, by a factor of 60.
Command | Iterations | Average (ms) | Overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
binompdf(19,0 | 1000 | 5 | 0.6 | 5 | 2.55MP/lirtosiast |
binomcdf(19,0 | 1000 | 20 | 0.6 | 20 | 2.55MP/lirtosiast |
1 or binompdf(19,0 | 1000 | 16 | 0.6 | 16 | 2.55MP/lirtosiast |
binompdf(19,1 | 1000 | 5 | 0.6 | 5 | 2.55MP/lirtosiast |
binompdf(19,.5 | 1000 | 296 | 0.6 | 296 | 2.55MP/lirtosiast |
Matrix Commands
When using matrix commands, remember that matrix multiplication is O(n^3). It's probably slower than other solutions for large matrices.
Command | Iterations | Average (ms) | Overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
[A]^^T //20x2 | 10000 | 9.3 | 0.6 | 8.7 | 2.55MP/lirtosiast |
[A]^^T //2x20 | 10000 | 9.4 | 0.6 | 8.8 | 2.55MP/lirtosiast |
[A]^^T //20x20 | 1000 | 62 | 0.6 | ~62 | 2.55MP/lirtosiast |
Home Screen Commands
Command | Iterations | Average (ms) | Loop overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
ClrHome | 1000 | 29 | 1.2 | 28 | kgmstwo |
Disp " | 1000 | 51 | 1.2 | 50 | kgmstwo |
Output(1,1," | 10000 | 3.8 | 1.2 | 2.6 | kgmstwo |
Output(1,1,"A | 10000 | 4.4 | 1.2 | 3.2 | kgmstwo |
Output(1,1,"AB | 10000 | 5.0 | 1.2 | 3.8 | kgmstwo |
Output(1,1,"ABC | 10000 | 5.6 | 1.2 | 4.4 | kgmstwo |
ClrHome | 1000 | 27 | .68 | 26 | kgmstwo |
Graphics Commands
Command | Iterations | Average (ms) | Loop overhead (ms) | Time (ms) | Username |
---|---|---|---|---|---|
Pxl-On(0,0 | 10000 | 2.9 | 1.2 | 1.7 | kgmstwo |
Pxl-Off(0,0 | 10000 | 2.9 | 1.2 | 1.7 | kgmstwo |
Pxl-Change(0,0 | 10000 | 2.9 | 1.2 | 1.7 | kgmstwo |
Horizontal -5 | 1000 | 36 | 1.2 | 35 | kgmstwo |
Horizontal -5 | 1000 | 35 | .68 | 34 | kgmstwo |
Vertical 5 | 1000 | 25 | 1.2 | 24 | kgmstwo |
ClrDraw | 1000 | 101 | 1.2 | 100 | kgmstwo |
StoPic Pic1 | 10000 | 4.7 | 1.2 | 3.5 | kgmstwo |
StoPic Pic1 | 10000 | 4.2 | .68 | 3.5 | kgmstwo |
RclPic Pic1 | 1000 | 28 | 1.2 | 27 | kgmstwo |
Pt-On(10,-10 | 10000 | 4.1 | 1.2 | 2.9 | kgmstwo |
Pt-On(10,-10 | 10000 | 4.5 | 1.2 | 3.3 | kgmstwo |
Pt-On(10,-10 | 10000 | 4.0 | .68 | 3.3 | kgmstwo |
:ZStandard:84→Xmin:72→Ymax:ZInteger | 100 | 220 | .68 | 220 | kgmstwo |
0->Xmin:1->DeltaX:0->Ymin:1->DeltaY | 1000 | 14 | .68 | 13 | kgmstwo |
0->Xmin:94->Xmax:-63->Ymin:0->Ymax | 1000 | 18 | .68 | 17 | kgmstwo |
Line(5,0,5,-62 | 1000 | 27 | .68 | 26 | kgmstwo |
Line(5,0,5,-62,0 | 1000 | 27 | .68 | 26 | kgmstwo |
Line(0,-5,94,-5 | 1000 | 37 | .68 | 36 | kgmstwo |
Line(0,-5,94,-5,0 | 1000 | 37 | .68 | 36 | kgmstwo |
Line(10,-10,10,-10 | 10000 | 7.2 | .68 | 6.5 | kgmstwo |
Line(10,-10,10,-10,0 | 10000 | 7.4 | .68 | 6.7 | kgmstwo |
note: multiple commands always on their own line.
Loop Overheads
Command | Average (ms) | Username |
---|---|---|
For(n,1,100000) | .83 | kgmstwo |
For(n,1,100000 | .69 | kgmstwo |
Calculators Used
Username | Model | OS version |
---|---|---|
kgmstwo | 84+SE | 2.43 |
lirtosiast | 84+ | 2.55MP |