diff --git a/src/Product.cc b/src/Product.cc index aaa36c03..5eb18dd6 100644 --- a/src/Product.cc +++ b/src/Product.cc @@ -1215,7 +1215,7 @@ static pair compute_offset1_and_limit1( } } -bool product_is_valid(const string& s, uint8_t domain, uint8_t subdomain) { +bool product_is_valid_slow(const string& s, uint8_t domain, uint8_t subdomain) { uint64_t product = decode_product_str(s); if (product == INVALID_PRODUCT) { return false; @@ -1370,7 +1370,7 @@ void product_speed_test(uint64_t seed) { time_fast += now() - start; start = now(); - bool is_valid_slow = product_is_valid(s, 1, 0xFF); + bool is_valid_slow = product_is_valid_slow(s, 1, 0xFF); time_slow += now() - start; if (((z & 0xF) == 0) || is_valid_slow || is_valid_fast) { @@ -1383,5 +1383,6 @@ void product_speed_test(uint64_t seed) { fprintf(stderr, "Total time (slow): %" PRId64 " usecs (%" PRIu64 " per product)\n", time_slow, time_slow / count); fprintf(stderr, "Total time (fast): %" PRId64 " usecs (%" PRIu64 " per product)\n", time_fast, time_fast / count); + fprintf(stderr, "Fast vs. slow speedup: %zux\n", static_cast(time_slow / time_fast)); fprintf(stderr, "Disagreements: %zu\n", num_disagreements); } diff --git a/src/Product.hh b/src/Product.hh index 5c19258e..78763113 100644 --- a/src/Product.hh +++ b/src/Product.hh @@ -5,14 +5,16 @@ #include #include -bool product_is_valid( +// product_is_valid_slow is Sega's implementation; product_is_valid_fast +// produces identical results but is about 7000 times faster. +bool product_is_valid_slow( const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF); bool product_is_valid_fast( const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF); bool product_is_valid_fast( - uint32_t product, uint8_t domain, uint8_t subdomain); + uint32_t product, uint8_t domain, uint8_t subdomain = 0xFF); bool decoded_product_is_valid_fast( - uint32_t product, uint8_t domain, uint8_t subdomain); + uint32_t product, uint8_t domain, uint8_t subdomain = 0xFF); std::string generate_product(uint8_t domain, uint8_t subdomain = 0xFF); std::unordered_map generate_all_products(uint8_t domain = 0xFF, uint8_t subdomain = 0xFF);