Prev Previous Post   Next Post Next
Old 06-28-2020, 11:16 AM   #1
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 307
Default What cause this script to run slower and slower?

I run this script in a blank project that only with 1 track and 1 selected media item. Then using loop and action: Item edit: Move duplicate of item to edit cursor
to copy the item many times.

Code:
function msg(value)
  reaper.ShowConsoleMsg(tostring(value) .. "\n")
end

reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)
count=0
local time_previous=os.clock()  --start time

for i=1, 10000 do
  reaper.Main_OnCommand(41309, 0)  --move item's duplicate
  --move edit cursor 5 seconds later
  reaper.SetEditCurPos(reaper.GetCursorPosition()+5, 0, 0)  
  count=count+1
  if count%1000==0 then  --record every 1000 times
    local time_now=os.clock()
    msg('Creat 1000 more items cost '..time_now-time_previous)
    time_previous=time_now  --update start time
  end
end

reaper.PreventUIRefresh(-1)
reaper.Undo_EndBlock('', -1)
The result is
Code:
Creat 1000 more items cost 0.016999999999825
Creat 1000 more items cost 0.050999999999476
Creat 1000 more items cost 0.095000000000255
Creat 1000 more items cost 0.15499999999975
Creat 1000 more items cost 0.20600000000013
Creat 1000 more items cost 0.25799999999981
Creat 1000 more items cost 0.30300000000079
Creat 1000 more items cost 0.36599999999999
Creat 1000 more items cost 0.41599999999926
Creat 1000 more items cost 0.46700000000055
If I change it from 10000 to 20000, the result is
Code:
Creat 1000 more items cost 0.016999999999825
Creat 1000 more items cost 0.052999999999884
Creat 1000 more items cost 0.094000000000051
Creat 1000 more items cost 0.14100000000053
Creat 1000 more items cost 0.18599999999969
Creat 1000 more items cost 0.23300000000017
Creat 1000 more items cost 0.28399999999965
Creat 1000 more items cost 0.33100000000013
Creat 1000 more items cost 0.37899999999991
Creat 1000 more items cost 0.4360000000006
Creat 1000 more items cost 0.48399999999947
Creat 1000 more items cost 0.54200000000037
Creat 1000 more items cost 0.58799999999974
Creat 1000 more items cost 0.6279999999997
Creat 1000 more items cost 0.67800000000079
Creat 1000 more items cost 0.75799999999981
Creat 1000 more items cost 0.8119999999999
Creat 1000 more items cost 0.88699999999972
Creat 1000 more items cost 0.96399999999994
Creat 1000 more items cost 1.0450000000001
It's obvious that the script is running slower and slower, I'm wondering what causes it?
dsyrock is offline   Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.