33#ifndef ALEPH_REPRODUCTIONS_SOURCE_DIR
34# define ALEPH_REPRODUCTIONS_SOURCE_DIR "reproductions"
48double seconds_for(
F &&operation)
50 const auto start = std::chrono::steady_clock::now();
52 return std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
59std::size_t population(
const Grid &frame)
61 std::size_t
count = 0;
63 for (
ca_size_t column = 0; column < frame.size(1); ++column)
64 if (frame.at({static_cast<ca_index_t>(row), static_cast<ca_index_t>(column)}) != 0)
74 constexpr std::size_t generations = 1000;
75 constexpr std::int64_t
offset = 32;
77 Grid
seed({side, side}, 0);
84 const double dense_seconds = seconds_for([&] { dense.run(generations); });
89 hashlife.set_alive(x,
y);
91 std::uint64_t actual_generations = 0;
92 const double hashlife_seconds
93 = seconds_for([&] { actual_generations = hashlife.run(generations); });
96 std::filesystem::create_directories(
root /
"results");
97 std::ofstream summary(
root /
"results" /
"game_of_life_bench.csv");
100 std::cerr <<
"Cannot write Game of Life benchmark\n";
103 summary <<
"engine,requested_generations,actual_generations,population,seconds\n"
104 <<
"dense_step," << generations <<
',' << generations <<
','
105 << population(dense.frame()) <<
',' << std::setprecision(12) << dense_seconds <<
'\n'
106 <<
"hashlife," << generations <<
',' << actual_generations <<
','
107 << hashlife.population() <<
',' << hashlife_seconds <<
'\n';
109 std::cout <<
"Game of Life Gosper gun benchmark (informational only)\n"
110 <<
" dense step: " << std::fixed << std::setprecision(6)
111 << dense_seconds <<
" s\n"
112 <<
" Hashlife: " << hashlife_seconds <<
" s"
113 <<
" (actual generations " << actual_generations <<
")\n";
114 if (actual_generations == generations)
115 std::cout <<
" population match: "
116 << (population(dense.frame()) == hashlife.population() ?
"yes" :
"no")
Internal helpers shared by the cellular-automata reproductions.
Hashlife engine for outer-totalistic binary cellular automata.
Lattice that adds boundary-aware access on top of a storage.
Synchronous double-buffered engine.
#define ALEPH_REPRODUCTIONS_SOURCE_DIR
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
void for_each_gosper_gun_cell(F &&visitor, const std::int64_t offset_x=0, const std::int64_t offset_y=0)
Visit every live coordinate in the canonical Gosper gun.
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Out-of-range neighbours behave as if the lattice ended.
Hashlife engine for outer-totalistic binary cellular automata.
Rule mechanisms for Aleph::CA.