briangu / klongpy

High-Performance Klong array language in Python.

Home Page:http://klongpy.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

\t

jibanes opened this issue · comments

Is it possible to measure the time taken by an instruction, i.e. in k or q you'd use \t

Hi, that's an interesting idea. Klong didn't have it so I never added it but it should be easy - I assume you ask because a lot of the README has timings, so it would definitely help clean it up!

OK, there are a few ways of handling this. I've got a branch going that is looking into adding this into the REPL, but you can also do this today with the .pc() operator:

define timeit via the following:

timeit::{[t0];t0::.pc();x@[];.pc()-t0}

and to use it:

fn::{1+1}
timeit(fn)

As you pointed out, i think it would be handy if these facilities were immediately available in the REPL, so i'll keep looking into that.

Hi, I added a ]T command to the REPL which both sticks to the Klong REPL style of ] and adds the Python native timeit capability:

Time one operation:

]T 1+1

Time 100 iterations

]T:100 1+1

Cheers!