13893Re: "ocaml_beginners":: interpolation with ints
- Jun 4, 20132013/06/04, Gabriel Scherer wrote:
> You could take as parametersNot really.
> ~t1 ~tdiff ~v1 ~vdiff
> but I don't think this will make a big difference (this purely-integer
> calculus is very fast already).
> Does this particular function already show high in your profile?
with (((v2 - v1) * (t - t1)) / (t2 - t1) + v1) there are 6 operations,
but 4 would be enough ((v_diff * (t - t1)) / t_diff + v1)
so I thought I could easily save a little there without making the
code too much complex.
Also I noticed that replacing /. 2.0 by *. 0.5 saves by twice. This
simple trick makes save a lot on my desktop computer, but there's not
that much difference there on the RPi.
$ cat >> interpolint.ml
let interg ~t1 ~t2 ~v1 ~v2 =
let v_diff = (v2 - v1)
and t_diff = (t2 - t1) in
let intervg ~t1 ~t_diff ~v1 ~v_diff t =
(v_diff * (t - t1)) / t_diff + v1
$ cat >> interpolint.mli
val interg :
t1:int -> t2:int ->
v1:int -> v2:int -> int * int
val intervg :
t1:int -> t_diff:int ->
v1:int -> v_diff:int -> int -> int
(** interpolation with intermediate calculus done,
not given as tuple *)
$ cat >> stress.ml
let stress4 () =
let t1, t2, v1, v2 = (1000, 1200, 2, 8) in
let v_diff, t_diff = interg ~t1 ~t2 ~v1 ~v2 in
for t = 1000 to 1200 do
let _ = intervg
~v1 ~v_diff t
- << Previous post in topic Next post in topic >>