#include <cstdio>    // for printf.
#include <chrono>	// for milliseconds, steady_clcok, duration_cast.

const int N = 10 * 1000;

struct point
{
	point(double x, double y)
		: x(x), y(y)
	{
	}

	double x;
	double y;
};

struct line
{
	line(double x1, double y1, double x2, double y2)
		: p_p1(new point(x1, y1)), p_p2(new point(x2, y2))
	{
	}

	~line() throw()
	{
		delete this->p_p2;
		delete this->p_p1;
	}

	point *p_p1;
	point *p_p2;
};

void f()
{
	auto * * array1 = new line *[N];

	auto st = std::chrono::steady_clock::now();
	for ( auto i = 0; i < N; i++ )
		array1[i] = new line(1, 2, 3, 4);
	for ( auto i = 0; i < N; i++ )
		delete array1[i];
	auto et = std::chrono::steady_clock::now();
	delete array1;

	std::printf("total = %lld ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(et - st).count());
	std::printf("avg. = %.1f us\n", std::chrono::duration_cast<std::chrono::milliseconds>(et - st).count() / static_cast<double>(N) * 1000);
}

int main()
{
	for ( auto i = 0; i < 3; i++ )
		f();

	getchar();
}

/*
C#はこれ

using System;

static class Test
{
	const int N = 100 * 1000;

	class point
	{
		public point() { }

		public point(double x, double y)
		{
			this.x = x;
			this.y = y;
		}

		public double x;
		public double y;
	};

	class line
	{
		public line(double x1, double y1, double x2, double y2)
		{
			this.p_p1.x = x1;
			this.p_p1.y = y1;
			this.p_p2.x = x2;
			this.p_p2.y = y2;
		}

		public point p_p1 = new point();
		public point p_p2 = new point();
	};

	static void f()
	{
		var array1 = new line[N];

		var st = DateTime.Now;
		for ( var i = 0; i < N; i++ )
			array1[i] = new line(1, 2, 3, 4);
		array1 = null;
		System.GC.Collect(3, GCCollectionMode.Default, true);
		var et = DateTime.Now;

		Console.WriteLine("total = {0:0.0} ms", (et - st).TotalMilliseconds);
		Console.WriteLine("avg. = {0:0.000} us", (et - st).TotalMilliseconds / (double)N * 1000);
	}

	static void Main()
	{
		for ( var i = 0; i < 10; i++ )
			f();

		Console.ReadKey();
	}

}

*/
