Simply skip first:

1
2
 
for i in 0..10 -> myArray |> Seq.skip i |> Seq.take offset 
By on 2/9/2009 11:54 AM ()

Thanks. Works great.

Would I be correct in thinking that using Sequences here avoids an allocation? My basic test seems to say yes, since the cpu utilization goes up when I make this change (and the gc is a bottleneck for me because i still haven't stomped out all the memory niavety from my code).

By on 2/9/2009 12:33 PM ()

Would I be correct in thinking that using Sequences here avoids an allocation? My basic test seems to say yes, since the cpu utilization goes up when I make this change[...]

Easy way to test this is to enter "#time;;" in the interactive session. It will then print out CPU and GC statistics after evaluation of each statement.

By on 2/16/2009 1:09 PM ()

Is there a way to achieve similar functionality from within an actual application, and not through FSI?

By on 2/17/2009 9:02 PM ()

Here is some sample code, only covering the time aspect. Any contributions handling the memory part are welcome:

1
2
3
4
5
6
  let Timed f x =
      let proc = System.Diagnostics.Process.GetCurrentProcess()
      let sw = System.Diagnostics.Stopwatch.StartNew()
      let sy = proc.TotalProcessorTime
      let r = f x
      printfn "Real: %-16O, CPU: %-16O -- %10O -> %O" sw.Elapsed (proc.TotalProcessorTime-sy) x r
By on 2/17/2009 11:51 PM ()

Yea the memory part is the hard part :( I actually don't care about GC generations so much as I do about memory usage over a period of time. But since I only care about space complexity for my particular problem, and not total space used, I could in theory probably estimate the memory usage based on watching the GC collection patterns since all comparisons would be relative to each other, and not universal.

By on 2/18/2009 6:51 AM ()

Adding space complexity to "#time;;" (or adding "#space;;") would be a very nice feature! (But, understandably a hard one to implement given the CLR.)

By on 4/10/2009 9:34 AM ()

It's correct that you avoid another array from being allocated.However, iterators are created of course, which brings some overhead as well.

By on 2/9/2009 9:10 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper