using Arrays - can it be faster ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
keylo
Posts: 52
Joined: 21 Oct 2020, 21:03

using Arrays - can it be faster ?

Post by keylo » 28 Jul 2021, 08:52

Hi all, is there a way to optimize the following codes so they can be faster? I'm dealing with big files so every nanosecond I save makes a huge difference at the end. The reason why I'm using arrays is that I need to modify them before writing them back.

thanks

Code: Select all

;~ read and store in arrays
data := []
file := FileOpen(WavFile, "rw","CP1252")
	loop, 
	{
	Mypos := File.Position
	
	data[A_Index] :=  File.ReadShort() 
	 if (mypos >= EndByte) 
		break
	}	
;~ *************************************

;~ write
file := FileOpen(WavFile, "rw","CP1252")
		loop, 
		{
		data := data[A_Index] * 0.5
		if data = 
			break
		File.Writeshort(data)
		}	
;~ ***************************************************		

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: using Arrays - can it be faster ?  Topic is solved

Post by swagfag » 28 Jul 2021, 09:42

yeah, like i was saying
swagfag wrote:
23 Jul 2021, 16:47
if u need to do DSP(which most often eventually ends up being the case), u dont do it in slow, interpreted languages
use a library. if u cant, write a dll/mcode, which would by far eclipse any ahk optimizations u might come up with
otherwise some optimization techniques are:
  • minimize work done(fewer iterations, fewer variable references, fewer method/property invocations, etc)
  • minimize ahk code that needs to run(if there's a function that does the thing, use it instead of replicating what its doing in ahk code)
  • for v1's "arrays" specifically, avoid indexing into them if possible. its not an O(1) operation
  • choose an appropriate data representation(if u dont need an array for a specific reason, dont stuff binary data into one)

also that write code u posted looks broken. there can only ever be 0 or 1 iterations

keylo
Posts: 52
Joined: 21 Oct 2020, 21:03

Re: using Arrays - can it be faster ?

Post by keylo » 28 Jul 2021, 17:39

swagfag wrote: ↑
23 Jul 2021, 16:47
if u need to do DSP(which most often eventually ends up being the case), u don't do it in slow, interpreted languages
LOL. you predicted it, it's funny.

But no, I don't wanna go deep into DSP now my skill is not there yet, some gentle wave manipulations will suffice for now.

Again your advice was on point regarding avoiding arrays.
I eliminated all arrays and did the file.read and file.write simultaneously in the same loop, no arrays. That increases the speed of the script by 3 folds. I'm more than happy with that........ for now. lol ;)

Thank you @swagfag

Post Reply

Return to “Ask for Help (v1)”