daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import times
  2.  
  3. type AThing = ref object
  4.   i: int
  5.  
  6. iterator items(a:AThing): int =
  7.  
  8.   when defined(dodefer):
  9.     defer:
  10.       a.i = 11
  11.   else:
  12.     a.i = 11
  13.  
  14.   for i in 0..a.i:
  15.     yield i
  16.  
  17. proc speed(n:int): int =
  18.   var j:int
  19.   var a = AThing(i:10)
  20.   var l = 0
  21.   for k in 0..<n:
  22.     j = 0
  23.     for i in a:
  24.       j += 1
  25.       if i > 5: break
  26.       l += 1
  27.     doAssert j > 0
  28.   doAssert a.i == 11
  29.   echo l
  30.   return j
  31.  
  32. import times
  33.  
  34. when defined(dodefer):
  35.   echo "using defer"
  36. else:
  37.   echo "no defer"
  38.  
  39. const N = 50000000
  40. var t = cpuTime()
  41. echo speed(N)
  42. echo cpuTime() - t
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top