/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 */
package org.jenetics.engine;

import static java.util.Objects.requireNonNull;

import java.time.Clock;
import java.time.Duration;
import java.time.Instant;

import org.jenetics.util.NanoClock;

/**
 * Timer implementation for measuring execution durations.
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @since 3.0
 * @version 3.0
 */
final class Timer {

	private final Clock _clock;

	private Instant _start;
	private Instant _stop;

	private Timer(final Clock clock) {
		_clock = requireNonNull(clock);
	}

	/**
	 * Start the timer.
	 *
	 * @return {@code this} timer, for method chaining
	 */
	public Timer start() {
		_start = _clock.instant();
		return this;
	}

	/**
	 * Stop the timer.
	 *
	 * @return {@code this} timer, for method chaining
	 */
	public Timer stop() {
		_stop = _clock.instant();
		return this;
	}

	/**
	 * Return the duration between two consecutive {@link #start()} and
	 * {@link #stop()} calls.
	 *
	 * @return the duration between two {@code start} and {@code stop} calls
	 */
	public Duration getTime() {
		return minus(_stop, _start);
	}

	private static Duration minus(final Instant a, final Instant b)  {
		final long seconds = a.getEpochSecond() - b.getEpochSecond();
		final long nanos = a.getNano() - b.getNano();

		return Duration.ofNanos(seconds*NanoClock.NANOS_PER_SECOND + nanos);
	}

	/**
	 * Return an new timer object which uses the given clock for measuring the
	 * execution time.
	 *
	 * @param clock the clock used for measuring the execution time
	 * @return a new timer
	 */
	public static Timer of(final Clock clock) {
		return new Timer(clock);
	}

	/**
	 * Return an new timer object with the default clock implementation.
	 *
	 * @return a new timer
	 */
	public static Timer of() {
		return of(NanoClock.systemUTC());
	}

}

@@ -889,16 +889,56 @@
 Instant;
+%0Aimport java.util.function.LongSupplier;
 %0A%0Aimport
@@ -1144,17 +1144,17 @@
 rsion 3.
-0
+1
 %0A */%0Afin
@@ -1190,16 +1190,27 @@
 nal 
-Clock _c
+LongSupplier _nanoC
 lock
@@ -1217,31 +1217,28 @@
 ;%0A%0A%09private 
-Instant
+long
  _start;%0A%09pr
@@ -1243,23 +1243,20 @@
 private 
-Instant
+long
  _stop;%0A
@@ -1273,31 +1273,42 @@
 Timer(final 
-Clock c
+LongSupplier nanoC
 lock) %7B%0A%09%09_c
@@ -1306,17 +1306,21 @@
 k) %7B%0A%09%09_
-c
+nanoC
 lock = r
@@ -1333,17 +1333,21 @@
 NonNull(
-c
+nanoC
 lock);%0A%09
@@ -1468,37 +1468,43 @@
 %09%09_start = _
-clock.instant
+nanoClock.getAsLong
 ();%0A%09%09return
@@ -1638,21 +1638,27 @@
  = _
-clock.instant
+nanoClock.getAsLong
 ();%0A
@@ -1902,558 +1902,553 @@
 urn 
-minus(_stop, _start);%0A%09%7D%0A%0A%09private static Duration minus(final Instant a, final Instant b)  %7B%0A%09%09final long seconds = a.getEpochSecond() - b.getEpochSecond();%0A%09%09final long nanos = a.getNano() - b.getNano();%0A%0A%09%09return Duration.ofNanos(seconds*NanoClock.NANOS_PER_SECOND + nanos);%0A%09%7D%0A%0A%09/**%0A%09 * Return an new timer object which uses the given clock for measuring the%0A%09 * execution time.%0A%09 *%0A%09 * @param clock the clock used for measuring the execution time%0A%09 * @return a new timer%0A%09 */%0A%09public static Timer of(final Clock clock) %7B%0A%09%09return new Timer(clock
+Duration.ofNanos(_stop - _start);%0A%09%7D%0A%0A%09/**%0A%09 * Return an new timer object which uses the given clock for measuring the%0A%09 * execution time.%0A%09 *%0A%09 * @param clock the clock used for measuring the execution time%0A%09 * @return a new timer%0A%09 */%0A%09public static Timer of(final Clock clock) %7B%0A%09%09requireNonNull(clock);%0A%09%09return clock instanceof NanoClock ? of() : new Timer(() -%3E nanos(clock));%0A%09%7D%0A%0A%09private static long nanos(final Clock clock) %7B%0A%09%09final Instant now = clock.instant();%0A%09%09return now.getEpochSecond()*NanoClock.NANOS_PER_SECOND + now.getNano(
 );%0A%09
@@ -2599,32 +2599,34 @@
 urn 
-of(NanoClock.systemUTC()
+new Timer(System::nanoTime
 );%0A%09

Simplify Timer class.