From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 7149B386101F for ; Fri, 9 Oct 2020 13:02:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7149B386101F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-210-wAA2aZGhMYCr7nn2sWneJQ-1; Fri, 09 Oct 2020 09:02:13 -0400 X-MC-Unique: wAA2aZGhMYCr7nn2sWneJQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D556DCE31B; Fri, 9 Oct 2020 13:02:12 +0000 (UTC) Received: from localhost (unknown [10.33.36.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7150E76667; Fri, 9 Oct 2020 13:02:12 +0000 (UTC) Date: Fri, 9 Oct 2020 14:02:11 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add performance test for Message-ID: <20201009130211.GA696171@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Oct 2020 13:02:51 -0000 --J/dobhs11T7y2rNN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This tests std::uniform_int_distribution with various parameters and engines. libstdc++-v3/ChangeLog: * testsuite/performance/26_numerics/random_dist.cc: New test. Tested powerpc64le-linux. Committed to trunk. --J/dobhs11T7y2rNN Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit f9919ba717dfaf6018b7e625bebc84a461477b52 Author: Jonathan Wakely Date: Fri Oct 9 12:07:36 2020 libstdc++: Add performance test for This tests std::uniform_int_distribution with various parameters and engines. libstdc++-v3/ChangeLog: * testsuite/performance/26_numerics/random_dist.cc: New test. diff --git a/libstdc++-v3/testsuite/performance/26_numerics/random_dist.cc b/libstdc++-v3/testsuite/performance/26_numerics/random_dist.cc new file mode 100644 index 00000000000..673992d1949 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/26_numerics/random_dist.cc @@ -0,0 +1,102 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include + +namespace counters +{ + __gnu_test::time_counter time; + __gnu_test::resource_counter resource; +} + + +template +void do_fill_with_uniform_ints(std::string name, Dist& d, Engine& e) +{ + using counters::time; + using counters::resource; + + std::vector r; + int n = 10000000; + { + const auto suffix = "-e" + std::to_string((int)std::log10(n)); + r.resize(n); + + start_counters(time, resource); + for (auto& x : r) + x = d(e); + stop_counters(time, resource); + report_performance(__FILE__, name+suffix, time, resource); + clear_counters(time, resource); + + d.reset(); + + start_counters(time, resource); + d.__generate(begin(r), end(r), e); + stop_counters(time, resource); + report_performance(__FILE__, name+"-range"+suffix, time, resource); + clear_counters(time, resource); + } +} + +template +void fill_with_uniform_ints(std::string name, Engine& e) +{ + using Dist = std::uniform_int_distribution; + using param_type = typename Dist::param_type; + + unsigned maxima[]{6, 10, 32, 100, 1000, 1024, (1<<16)-1, 1<<16, 1<<20, -1u}; + for (auto hi : maxima) + { + Dist dist(param_type{0, hi}); + std::ostringstream s; + s << name << "-uniform_int-" << (dist.max() - dist.min()); + do_fill_with_uniform_ints(s.str(), dist, e); + } +} + +int main() +{ + using namespace std; + + std::mt19937 mt; + fill_with_uniform_ints("mt19937", mt); + std::mt19937_64 mt64; + fill_with_uniform_ints("mt19937_64", mt64); + + // Same as std::mt19937 but using uint32_t not uint_fast32_t for result_type + using mt19937_32 = std::mersenne_twister_engine; + mt19937_32 mt32; + fill_with_uniform_ints("mt19937_32", mt32); + + std::minstd_rand0 lcg; + fill_with_uniform_ints("minstd_rand0", lcg); + + // Same as std::minstd_rand0 but using uint32_t not uint_fast32_t + using minstd_rand0_32 = std::linear_congruential_engine; + minstd_rand0_32 lcg_32; + fill_with_uniform_ints("minstd_rand0_32", lcg_32); + + return 0; +} + --J/dobhs11T7y2rNN--