Hi all !
This test with an immutable list class shows how you can get a copy with
one changed element in 12 microseconds while the same copy with one
changed element with a non-immutable array takes 15 milliseconds.
The tests are repeated, but it's the second test that counts.
let mutable a = ImmList<int>.Empty
let mutable b = null;
let mutable c = null;
a <- a.AddFirstRange([1 .. 10000000])
let stopWatch = System.Diagnostics.Stopwatch.StartNew()
b <- a.Update(5000000,-1);
stopWatch.Stop()
printfn "%f" stopWatch.Elapsed.TotalMilliseconds
//6.442300
printfn "%A %A" (a.TryGet(5000000)) (b.TryGet(5000000));
//5000001 -1
let stopWatch = System.Diagnostics.Stopwatch.StartNew()
c <- a.Update(5000000,-1);
stopWatch.Stop()
printfn "%f" stopWatch.Elapsed.TotalMilliseconds
//0.011900
let a = [|1 .. 10000000|]
let stopWatch = System.Diagnostics.Stopwatch.StartNew()
let b = Array.copy a;
b.[5000000] <- -1
stopWatch.Stop()
printfn "%f" stopWatch.Elapsed.TotalMilliseconds
//15.108700
printfn "%i %i" a.[5000000] b.[5000000];
//5000001 -1
let stopWatch = System.Diagnostics.Stopwatch.StartNew()
let c = Array.copy a;
c.[5000000] <- -1
stopWatch.Stop()
printfn "%f" stopWatch.Elapsed.TotalMilliseconds
//14.760200
Cheers,
Erling Hellenäs
On 2016-10-05 02:34, Xiao-Yong Jin wrote:
On Oct 4, 2016, at 2:01 PM, Louis de Forcrand <[email protected]> wrote:
Maybe add a third setting to 9!:53 which copies a at the start of a tacit verb
involving in place operations?
This is a good compromise between speed and sensible intuition.
I guess a memcpy only when in-place-operation is detected wouldn't be slower in
general than previous non-in-place operations.
This could certainly be the default option.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm