| T O P I C R E V I E W |
| s.manolopo |
Posted - 08/26/2004 : 05:51:19 AM Hi, I've written the script below for data analysis. echo=1; wo -d beamon; nrow=wks.nrows; ncol=wks.ncols; loop (i,1,ncol) { loop (j,1,nrow) { data=%(%H,i,j); if(data <= 10000) %(%H,i,j)=0; }; };
My problem is that it takes around 10 min (!!!) to execute for a dataset of 128 columns and 1000 rows on a P4 (1.9GHz) with 250MB RAM with no other application running... Is this typical or is my script not efficient ? I would appreciate the answer as it is my first attempt in Labtalk programming and would like to know if it is worthy pursuing or will it be better to switch to a different programming language?.. Thanks. Spyros.
Edited by - s.manolopo on 08/26/2004 05:51:53 AM |
| 5 L A T E S T R E P L I E S (Newest First) |
| rlewis |
Posted - 08/26/2004 : 11:14:11 PM I did a few timing tests with a 1.4GHZ 512 Mb WIn-XP machine using a worksheet with 1000 rows and 128 cols and found the following...
When Origin is the only Application running Spyros LT script ~ 80 sec Ternary Operator script outlined by Mike Buess .... ~13 sec Treplace function <1 sec
When Origin is carrying a large project and many applications are running in the background (i.e. when available physical memory is limiting) Spyros's LT script ~ 20 min Ternary Operator script outlined by Mike Buess .... ~10 min Treplace function <1 sec
The LT Treplace function was even quicker than an OriginC function (~ 6sec) using row by row comparison. However I also found that the Treplace works really well only when worksheet columns were used.
Thus ... LT script such as ... for(i=1;i<128;i++) col($(i))=treplace(col($(i),1000,0,1); works really well whereas LT script using the corresponding dataset names was not very satisfactory.
|
| rlewis |
Posted - 08/26/2004 : 11:10:01 PM I did a few timing tests with a 1.4GHZ 512 Mb WIn-XP machine and found a worksheet with 1000 rows and 128 cols and found the following
When Origin is the only Application running Spyros LT script ~ 80 sec Ternary Operator script outlined by Mike Buess .... ~13 sec Treplace function <1 sec
When Origin is carrying a large project and many applications are running in the background (i.e. when available physical memory is limiting)
Spyros's LT script ~ 20 min Ternary Operator script outlined by Mike Buess .... ~10 min Treplace function <1 sec
The LT Treplace function was even quicker than an OriginC function (~ 6sec) using row by row comparison.
However I did find the Treplace only when worksheet columns were used.
Thus ... LT script such as ... for(i=1;i<128;i++) col($(i))=treplace(col($(i),1000,0,1); works really well whereas LT script teh corresponding dataset names was not very satisfactory.
|
| Mike Buess |
Posted - 08/26/2004 : 10:36:19 AM Hi Spyros,
A common LabTalk programming mistake is using 'win -c wksname' to destroy a wks and thinking that also deletes its column datasets. It doesn't... win -c only destroys the wks window. That's why I suggested you try 'list s' and look for datasets that once belonged to worksheets. 'del -a' will not delete those datasets.
In Origin 6.1 (I think) and higher use 'win -cd wksname' to delete the window and column datasets.
In lower versions you must use something like this...
win -o wksname { repeat wks.ncols {del col(1)}; // delete all columns }; win -c wksname; // delete wks window
...If you do have Origin 6.1 (SR2) or higher the tReplace function is definitely the way to go when dealing with thresholds. Much faster even than the ternary operator.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 08/26/2004 10:42:30 AM |
| s.manolopo |
Posted - 08/26/2004 : 10:10:31 AM Hi Mike, I've tried your mod. Think's improved a bit, but only mildly.. Elapsed time shown with a watch command is 529.406 sec. (!!!). I've also included a del -a at the beginning of script. There must be something else going on.. Thanks anyway.. Cheers, Spyros. |
| Mike Buess |
Posted - 08/26/2004 : 08:13:31 AM Hi Spyros,
OriginC or any other compiled language will be faster than LabTalk but 10 minutes seems excessive. I just timed your script on a 128x1000 wks and it took 76 seconds on a P4 (1.4G) w/256MB. If you've been doing this sort of test a lot you might have several temporary datasets left over in memory. Do a 'list s' in the script window to find out.
Also, there are much more efficient ways to apply thresholds in LabTalk. The ternary operator will be at least twice as fast as your current row-by-row comparison...
loop (i,1,ncol) { %(%H,i)=%(%H,i)<=10000?0:%(%H,i); };
And LabTalk's tReplace function will be even faster.
Mike Buess Origin WebRing Member |
|
|