Old 05-25-2016, 03:17 AM   #1
ACall231
Human being with feelings
 
ACall231's Avatar
 
Join Date: Apr 2016
Location: Maumee, OH
Posts: 21
Default Speed of EEL vs. LUA for ReaScript

I have started to delve into writing a script to automatically insert certain kinds of notes into a MIDI track.

I am initially using LUA because it seems to be more oriented to a general programming language than EEL. My present script can quickly insert a few notes into the MIDI track.

From looking at the documentation in ReaScript there is a hint that EEL is significantly faster than LUA.

I have a question: if I were to write similar scripts in LUA and EEL to insert 1000 MIDI notes, would EEL be any faster than LUA, or would the reaper cycle be the limiting factor and the relative speeds would be about the same?

Thanks...Archie
ACall231 is offline   Reply With Quote
Old 05-25-2016, 04:40 AM   #2
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,411
Default

Do it in Lua. is very fast. There is a post somewhere here with some tests. It is not significantly faster. The advantages of Lua are worth it.
heda is offline   Reply With Quote
Old 05-25-2016, 04:59 AM   #3
ACall231
Human being with feelings
 
ACall231's Avatar
 
Join Date: Apr 2016
Location: Maumee, OH
Posts: 21
Default

Thank you Hector. I just changed my LUA script, and it pumps in over 100 notes with no perceived delay. I'll try to find that old post on speed of LUA...Archie
ACall231 is offline   Reply With Quote
Old 05-25-2016, 07:05 AM   #4
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,631
Default

Quick tip....
Code:
local t0,t1
local function showTime(msg,a,b)
  reaper.ShowConsoleMsg(msg..(b-a).."\n")
end

-- fast
t0=reaper.time_precise()
for i=1,100000,1 do
  reaper.CountSelectedTracks() -- random function
end
t1=reaper.time_precise()
showTime("Fast:   ",t0,t1)

--faster
local r=reaper
t0=reaper.time_precise()
for i=1,100000,1 do
  r.CountSelectedTracks()
end
t1=reaper.time_precise()
showTime("Faster:  ",t0,t1)

--fastest
local rf=reaper.CountSelectedTracks
t0=reaper.time_precise()
for i=1,100000,1 do
  rf()
end
t1=reaper.time_precise()
showTime("Fastest: ",t0,t1)
... there's a surprising difference between the first and last two. The last is the fastest, but it seems that the easiest way to "upgrade" all of our scripts is to put...
Code:
local reaper=reaper
... in every file (and make sure everything else is local).
snooks is offline   Reply With Quote
Old 05-28-2016, 10:03 AM   #5
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,752
Default

Quote:
Originally Posted by ACall231 View Post
I have a question: if I were to write similar scripts in LUA and EEL to insert 1000 MIDI notes, would EEL be any faster than LUA, or would the reaper cycle be the limiting factor and the relative speeds would be about the same?

Thanks...Archie
Inserting and deleting notes or CCs are relatively slow functions and REAPER's internal processing would be the limiting factor. I tested the speed of Lua vs EEL for inserting CCs (using local functions as described by snooks) and there is no difference in speed between Lua and EEL.

In Lua, local variables are accessed much faster than global (default) variables, so it is usually advisable to declare variables local, particularly if they are going to be used a lot.

Last edited by juliansader; 05-29-2016 at 02:21 AM.
juliansader is offline   Reply With Quote
Old 05-28-2016, 10:57 AM   #6
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 10,243
Default

Assuming the scripts are designed non-pathologically, there should be not be a massive performance difference between various reascript platforms when doing anything that doesn't involve processing audio samples (which will necessarily be orders of magnitude more performance intensive than not processing audio samples). Even audio processing is probably fine in Lua if you are doing stuff in response to user input (as opposed to real time).
schwa is offline   Reply With Quote
Old 05-28-2016, 11:07 AM   #7
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,241
Default

Quote:
Originally Posted by schwa View Post
Assuming the scripts are designed non-pathologically, there should be not be a massive performance difference
For anyone like me who didn't understand this sentence and had to look it up, "pathological" = badly written, inefficient, awkward, etc coding.
Lokasenna is online now   Reply With Quote
Old 05-28-2016, 11:17 AM   #8
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,528
Default

schwa, do you have any developement with lua as JSFX alternative (like protoplug)?
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate
mpl is offline   Reply With Quote
Old 05-28-2016, 11:41 AM   #9
ACall231
Human being with feelings
 
ACall231's Avatar
 
Join Date: Apr 2016
Location: Maumee, OH
Posts: 21
Default

juliansader, hector, and heda:

I tested your tip on local vars for my computer and saw about a 100% speedup on your test script.

LUA is the way to go. I picked up the syntax in about 5 minutes. I really like the way you do not have to mess around between floating and integer vars.

I have started to use ZeroBrane as an IDE to augment the built in LUA editor. It seems to work well. Are you using something similar?

Another quick question: From looking at the API, there is a function to select all midi notes. However I can't find a function to delete all the selected notes. I can manually press the Delete key to delete them, but is there an API function to automatically send the Delete?

Thanks again for your valuable assistance...Archie
ACall231 is offline   Reply With Quote
Reply

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 12:43 PM.


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