<commit_before>package stormpot.benchmark;

import java.util.concurrent.locks.LockSupport;

/**
 * The Clock improves upon {@link System#currentTimeMillis()} in that it can be
 * stopped and manually ticked forward. This is useful for testability.
 * @author cvh
 *
 */
public final class Clock {

  private static volatile long now;
  
  private static final Ticker ticker = new Ticker();
  
  private Clock() { /* static utility class */ }
  
  /**
   * Advance the clock to the current time.
   * @return The new current time, in milliseconds since the epoch.
   */
  public static long tick() {
    return now = System.currentTimeMillis();
  }

  /**
   * Advance the clock by exactly one millisecond, regardless of what the
   * actual time may be.
   * Note that this method is racy, and is technically only safe to call by
   * a single thread at a time, and when the automatic ticking of the clock<commit_msg>add note on the Clock about performance and accuracy.<commit_after>package stormpot.benchmark;

import java.util.concurrent.locks.LockSupport;

/**
 * The Clock improves upon {@link System#currentTimeMillis()} in that it can be
 * stopped and manually ticked forward. This is useful for testability.
 * 
 * It also turns out that a simple volatile read is significantly faster than
 * calling {@link System#currentTimeMillis()}, but the improvement in reading
 * performance comes at a cost of accuracy. Of what I've observed, the clock
 * can sometimes be off by some 10-odd milliseconds - sometimes more. It varies.
 * @author cvh
 */
public final class Clock {

  private static volatile long now;
  
  private static final Ticker ticker = new Ticker();
  
  private Clock() { /* static utility class */ }
  
  /**
   * Advance the clock to the current time.
   * @return The new current time, in milliseconds since the epoch.
   */
  public static long tick() {
    return now = System.currentTimeMillis();
  }

  /**
   * Advance the clock by exactly one millisecond, regardless of what the
   * actual time may be.
   * Note that this method is racy, and is technically only safe to call by
   * a single thread at a time, and when the automatic ticking of the clock
{'fraction_non_alphanumeric': 0.07537688442211055, 'fraction_numerical': 0.0009136592051164915, 'mean_word_length': 3.4064386317907447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '416690', 'n_tokens_mistral': 590, 'n_tokens_neox': 570, 'n_words': 283}