// compile with: dmd vector.d -inline -O -release -w -g // debug with: windbg vector.exe import std.stdio; import std.string; import std.c.windows.windows; struct Vector3(T) { T x, y, z; string toString() { return "(" ~ format("%g", x) ~ " " ~ format("%g", y) ~ " " ~ format("%g", z) ~ ")"; } void opAddAssign(Vector3 v) { x += v.x; y += v.y; z += v.z; } void opSubAssign(ref Vector3 v) { x += v.x; y += v.y; z += v.z; } Vector3 opMul(T s) { return Vector3(x * s, y * s, z * s); } } alias Vector3!(float) Vector3f; int main(char[][] args) { long start, end, freq; QueryPerformanceFrequency(&freq); Vector3f v1 = {1.0f, 2.0f, 3.0f}; Vector3f v2 = {4.0f, 5.0f, 6.0f}; writefln(v1, " ", v2); // first QueryPerformanceCounter(&start); for (int i=0; i<0x40FFFFFF; i++) { v1 += v2 * 3.0f; } QueryPerformanceCounter(&end); writefln("%.3fs", (end - start) / cast(float)freq); // second QueryPerformanceCounter(&start); for (int i=0; i<0x40FFFFFF; i++) { v1 -= v2 * 3.0f; } QueryPerformanceCounter(&end); writefln("%.3fs", (end - start) / cast(float)freq); // third QueryPerformanceCounter(&start); for (int i=0; i<0x40FFFFFF; i++) { v1.x += v2.x * 3.0f; v1.y += v2.y * 3.0f; v1.z += v2.z * 3.0f; } QueryPerformanceCounter(&end); writefln("%.3fs", (end - start) / cast(float)freq); writefln(v1, " ", v2); return 0; }