2

While testing someone else's code on coliru, I noticed that std::chrono::system_clock::now().time_since_epoch() returns the same values on multiple runs. I tested the following code with g++ and clang++ on coliru.

#include <iostream>
#include <chrono>
int main()
{
    auto seed = std::chrono::system_clock::now().time_since_epoch().count();
    std::cout << seed << "\n";
    std::cout << std::chrono::system_clock::now().time_since_epoch().count() << "\n";

    return 0;
}

Output:

g++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out

1433249917642594133

1433249917642674289

It does work as expected on ideone and obviously on my computer.

Does anyone know why coliru returns the same values on every run?

Avi Ginsburg
  • 10,323
  • 3
  • 29
  • 56

1 Answers1

1

Coliru caches the results of each snippet, so this is expected behaviour.

You can force a re-run by trivially altering the source file (by, say, adding more whitespace, or changing the contents of a comment).

(Source: I know the author.)

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055