PDA

View Full Version : Timing Functions (UserScripts)



Shawn
05-06-2021, 02:08 PM
TLDR: What's a good way to time the speed of my script?
Inside a function or when I call the function?
I'm currently using performance.now() to time, should I use this?



I'm working on a main shop ABer and I'm working on solving pet captcha portion.
I know there's a publicly-available method of solving this captcha but I decided to try to work on my own.

After completing mine, I believe I might have something that's more accurate and faster.
The improved accuracy is a certainty, but I want to make sure that my captcha solving function is not slowed down by this.
How should I measure how long my function takes to solve?



This is what I'm doing currently:


myOwnSolver(img)
publicSolver(img)

function myOwnSolver(img) {
let a = performance.now()

... function stuff ...

let b = performance.now()
console.log(`My Own: ${b-a} ms`);
}

function publicSolver(img) {
let a = performance.now()

... function stuff ...

let b = performance.now()
console.log(`Public: ${b-a} ms`);
}


Should I be timing when I call the function instead of inside the function itself?


let a = performance.now()
myOwnSolver(img)
let b = performance.now()
console.log(`My Own: ${b-a} ms`);


let a = performance.now()
publicSolver(img)
let b = performance.now()
console.log(`My Own: ${b-a} ms`);

function myOwnSolver(img) {

... function stuff ...

}

function publicSolver(img) {

... function stuff ...

}


:o_o:

Using my current method of timing, here are the results:

Solver is my most accurate captcha solver,
Super is an approximation of Solver for speed,
Free is the publicly-available solver



Solver:
127,17
31.000000017229468 ms

Super:
131,20
3.1350000062957406 ms

Free:
131,20
Free: 827.8300000238232 ms

npm
05-07-2021, 12:40 PM
You should be measuring the time outside the function as you're trying to measure the total time until you get the result from the function. Btw great job I never put time into finding an optimal solution for the captcha :o_o:

Shawn
05-08-2021, 03:20 PM
You should be measuring the time outside the function as you're trying to measure the total time until you get the result from the function. Btw great job I never put time into finding an optimal solution for the captcha :o_o:
Thank you, this makes sense.



Glad to say that I've completed auto-haggle + captcha completion + form submission that completes the buy page consistently in <10ms
Haggling takes about 0.1 ms
Solving captcha takes <10 ms
Practical AB speed really depends on how fast the browser loads haggle form + captcha image.



I would really LOVE to release this but tbh it's waaaaay too fast to be released for general use here for now.
I'd need to implement a random delay when buying, which I'll leave for another day.

Sarada
05-08-2021, 03:49 PM
I'm not sure how to time your function or introduce randomized delays, but I suspect if you can create a bell curve randomized time, it would look more human than an even distribution of times. IE if use a bell curve and have a delay between 1 and 9 seconds it'll more often refresh closer to 5 seconds than it will at the extremes of 1 second and 9 seconds.

Shawn
05-08-2021, 03:58 PM
I'm not sure how to time your function or introduce randomized delays, but I suspect if you can create a bell curve randomized time, it would look more human than an even distribution of times. IE if use a bell curve and have a delay between 1 and 9 seconds it'll more often refresh closer to 5 seconds than it will at the extremes of 1 second and 9 seconds.

Yes, I've thought of, and seen easily implementable bell curve distributions of random numbers. Thank you for that suggestion!

And don't worry, I've got timing my functions down as well as implementing the random delays in the future!