Giter Club home page Giter Club logo

compare-code-speed-gui-ahkv2-optimize-scripts-for-speed's Introduction

Optimize AHKv2 for speed

Optimize AHKv2 Code for Speed

image

Credits:

I'm not going to try to rewrite the original post text, a lot of it is great and should be read from the source https://www.autohotkey.com/boards/viewtopic.php?f=7&t=6413 Many of the conventions such as #NoEnv and #SetBatchLines are defunct, but the rest is very valuable. I have restructured the tests for ahkv2.

tests include:

  • a few tips for IF checking of Boolean values
  • Avoid spreading math over multiple lines and using variable for intermediate results if they are only used once. As much as possible condense math into one line and only use variables for storing math results if you need the results being used multiple times later.
  • Terinary
  • Variable expressions

Commas and Combined lines aren't faster in v2; with caveats.

v2 Guide / Tutorial

Over the course of 3 months, I've learned some optimization tricks. After a deeper dive and some reflection, I've found I had some misconceptions on their transient ability in moving to AHKv2. I noticed a lot of this syntax in experienced community members' scripts, including mine, and I want to share what I've found.

https://github.com/samfisherirl/Compare-Code-Speed-GUI-AHKv2

The tests

Defining variables by lines and commas

tests are shortened for brevity

;test 1
t1a := 1
t1b := 1
t1c := 1
t1d := 1

;test 2
 t2f := t2g := t2h := t2i := t2j := 1

;test3
t3a := 1, t3b := 1, t3c := 1, t3d := 1

AHKv1 results =

	;test1 0.240315

	;test2 0.132753

	;test3 0.168953

ahkv2 results =

	 ;test1 0.00124844 (50% + faster)

	;test2 0.00259254

	;test3 0.00274485

We can see combining variables on a single line in these examples are no longer faster but hamper the code. We'll find out this is different with function calls.

Let's do it again with functions

these functions are across all tests ; condensed

	e() {   y := 999*222
	   return y }

	f() {  y := 999*222
	   return y }
	g() {   y := 999*222
	   return y }

test1

	a := e()
	b := f()
	c := g()

test2

a := e(),b := f(),c := g()

test3

    a := e()
,b := f()
,c := g()

results

	;test1 0.01627 (50% slower)
	;test2 0.01098
	;test3 0.011008

Even shortened conditionals aren't faster with combined lines

;test1

x := true

if x
   z:=1, a:=2, b:=1, c:=2

;test2

	x := true

	if x
	{
	   z:=1
	   a:=2
	   b:=1
	   c:=2
	}
  • test1 0.0026

  • test2 0.00180 ;30% faster

compare-code-speed-gui-ahkv2-optimize-scripts-for-speed's People

Contributors

samfisherirl avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

poa00

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.