Skip to content

Instantly share code, notes, and snippets.

@PhilipWitte
Last active December 24, 2015 08:39
Show Gist options
  • Save PhilipWitte/6772348 to your computer and use it in GitHub Desktop.
Save PhilipWitte/6772348 to your computer and use it in GitHub Desktop.
Nimrod's Times.EpochTime doesn't seem to measure correctly.
import StrUtils, Times
type Vector = tuple[x, y, z, w:float]
proc new(T:typedesc[Vector], x, y, z, w:float): Vector {.noSideEffect, noInit, inline.} =
result.x = x
result.y = y
result.z = z
result.w = w
proc `$`(this:Vector): string {.noSideEffect, inline.} =
return
$(this.x) & ", " &
$(this.y) & ", " &
$(this.z) & ", " &
$(this.w)
proc `+=`(this:var Vector, vec:Vector) {.noSideEffect, inline.} =
this.x += vec.x
this.y += vec.y
this.z += vec.z
this.w += vec.w
proc `-=`(this:var Vector, vec:Vector) {.noSideEffect, inline.} =
this.x -= vec.x
this.y -= vec.y
this.z -= vec.z
this.w -= vec.w
proc benchmark =
var
a = Vector.new(0, 0, 0, 0)
b = Vector.new(1, 1, 1, 1)
sum: float
let
count = stdin.readLine().parseInt()
repeat = stdin.readLine().parseInt() * 1000
for c in 0 .. count:
let start = epochTime()
for t in 0 .. repeat:
a += b
b -= a
sum += epochTime() - start
echo a
echo b
echo "result: ", (sum / count.float)
benchmark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment