Great to hear that you got on par with C performance-wise! One other thing I'd like to draw attention to is allocation of [column]: in C code, it is via [alloca], so it gets freed as soon as the control exits the function, but in ATS code, [malloc] (or some such) is used, and then, a cast from [arrayptr] to [arrayref] means we are leaving it to GC to deallocate [column].
I suggest introducing a function that takes uninitialized [column] as parameter, and performs the rest of the computation. Then [levenshtein] is tasked with allocation and freeing the array. Plus, somebody could plug another allocation strategy this way. There was a thread about using [alloca] in ATS somewhere. сб, 21 июл. 2018 г., 6:18 Vanessa McHale <[email protected]>: > It doesn't seem to affect things in a way that I can measure, though > thankfully with Artyom's suggestions the code is now as fast as C (or at > least, I can't reliably measure any difference in the two) :) > > On 07/20/2018 08:39 AM, gmhwxi wrote: > > fun loop2 { i : nat | i > 0 && i <= n+1 } .<n-i+1>. (x : int(i)) : > > void = > > if x <= sz2i(s2_l) then > > { > > val () = column[0] := x > > val p0 = arrayref2ptr(column) > > val p1 = ptr_succ<int>(p0) > > val () = let > > fun > > inner_loop > > { j : nat | j > 0 && j <= m+1 } .<m-j+1>. > > (y : int(j), p0: ptr, p1: ptr, last_diag : int) : void = > > if y <= sz2i(s1_l) then > > let > > fun min_3(x : int, y : int, z : int) : int = min(x, > > (min(y, z))) > > > > val c0 = $UN.ptr0_get<int>(p0) > > val c1 = $UN.ptr0_get<int>(p1) > > val c1_new = min_3(c0+1, c1+1, last_diag + > > bool2int(s1[y - 1]=s2[x - 1])) > > val () = $UN.ptr0_set<int>(p1, c1_new) > > in > > inner_loop(y + 1, p1, ptr_succ<int>(p1), c1) > > end > > > > inner_loop(1, p0, p1, x - 1) > > end > > val () = loop2(x + 1) > > } > > -- > You received this message because you are subscribed to the Google Groups > "ats-lang-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/ats-lang-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ats-lang-users/108e32af-a016-2735-1307-9984df9a334f%40iohk.io > . > -- You received this message because you are subscribed to the Google Groups "ats-lang-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/ats-lang-users. To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAKO6%3Dqga0%2Bvg5wAtbhVOC4zEBJZSTph6M%3DWAKJUsPiroZVEdZQ%40mail.gmail.com.
