Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
2133-Implement-dummy-generator-to-measure-plug-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2133-Implement-dummy-generator-to-measure-plug-in-overhea.patch of Package erlang
From 9de5e230ca6ab13181560990123d6fd726967d1e Mon Sep 17 00:00:00 2001 From: Raimo Niskanen <raimo@erlang.org> Date: Mon, 14 Mar 2022 15:25:27 +0100 Subject: [PATCH 3/4] Implement dummy generator to measure plug-in overhead --- lib/stdlib/doc/src/rand.xml | 6 ++++- lib/stdlib/src/rand.erl | 49 ++++++++++++++++++++++++++++++---- lib/stdlib/test/rand_SUITE.erl | 4 +-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/lib/stdlib/doc/src/rand.xml b/lib/stdlib/doc/src/rand.xml index e7a2823bc0..4a9d2d1ea4 100644 --- a/lib/stdlib/doc/src/rand.xml +++ b/lib/stdlib/doc/src/rand.xml @@ -4,7 +4,7 @@ <erlref> <header> <copyright> - <year>2015</year><year>2021</year> + <year>2015</year><year>2022</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -376,6 +376,10 @@ tests. We suggest to use a sign test to extract a random Boolean value.</pre> <name name="exs64_state"/> <desc><p>Algorithm specific internal state</p></desc> </datatype> + <datatype> + <name name="dummy_state"/> + <desc><p>Algorithm specific internal state</p></desc> + </datatype> </datatypes> <funcs> diff --git a/lib/stdlib/src/rand.erl b/lib/stdlib/src/rand.erl index d5906d3730..b2c3d4a557 100644 --- a/lib/stdlib/src/rand.erl +++ b/lib/stdlib/src/rand.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2015-2020. All Rights Reserved. +%% Copyright Ericsson AB 2015-2022. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -88,7 +88,7 @@ %% This depends on the algorithm handler function -type alg_state() :: exsplus_state() | exro928_state() | exrop_state() | exs1024_state() | - exs64_state() | term(). + exs64_state() | dummy_state() | term(). %% This is the algorithm handling definition within this module, %% and the type to use for plugins. @@ -132,7 +132,8 @@ %% Algorithm state -type state() :: {alg_handler(), alg_state()}. -type builtin_alg() :: - exsss | exro928ss | exrop | exs1024s | exsp | exs64 | exsplus | exs1024. + exsss | exro928ss | exrop | exs1024s | exsp | exs64 | exsplus | + exs1024 | dummy. -type alg() :: builtin_alg() | atom(). -type export_state() :: {alg(), alg_state()}. -type seed() :: [integer()] | integer() | {integer(), integer(), integer()}. @@ -141,7 +142,7 @@ state/0, export_state/0, seed/0]). -export_type( [exsplus_state/0, exro928_state/0, exrop_state/0, exs1024_state/0, - exs64_state/0]). + exs64_state/0, dummy_state/0]). %% ===================================================================== %% Range macro and helper @@ -710,7 +711,12 @@ mk_alg(exro928ss) -> uniform=>fun exro928ss_uniform/1, uniform_n=>fun exro928ss_uniform/2, jump=>fun exro928_jump/1}, - fun exro928_seed/1}. + fun exro928_seed/1}; +mk_alg(dummy=Name) -> + {#{type=>Name, bits=>58, next=>fun dummy_next/1, + uniform=>fun dummy_uniform/1, + uniform_n=>fun dummy_uniform/2}, + fun dummy_seed/1}. %% ===================================================================== %% exs64 PRNG: Xorshift64* @@ -1373,6 +1379,39 @@ exrop_jump([S__0|S__1] = _S, S0, S1, J, Js) -> exrop_jump(NewS, S0, S1, J bsr 1, Js) end. +%% ===================================================================== +%% dummy "PRNG": Benchmark dummy overhead reference +%% +%% As fast as possible - return a constant; to measure overhead. +%% +%% ===================================================================== + +-opaque dummy_state() :: 0..?MASK(58). + +dummy_uniform(_Range, State) -> {1, State}. +dummy_next(R) -> {?BIT(57), R}. +dummy_uniform(State) -> {0.5, State}. + +%% Serious looking seed, to avoid at least seed test failure +%% +dummy_seed(L) when is_list(L) -> + case L of + [X] when is_integer(X) -> + ?MASK(58, X); + [X|_] when is_integer(X) -> + erlang:error(too_many_seed_integer); + [_|_] -> + erlang:error(non_integer_seed) + end; +dummy_seed(X) when is_integer(X) -> + {Z1, _} = splitmix64_next(X), + ?MASK(58, Z1); +dummy_seed({A1, A2, A3}) -> + {_, X1} = splitmix64_next(A1), + {_, X2} = splitmix64_next(A2 bxor X1), + {Z3, _} = splitmix64_next(A3 bxor X2), + ?MASK(58, Z3). + %% ===================================================================== %% Mask and fill state list, ensure not all zeros %% ===================================================================== diff --git a/lib/stdlib/test/rand_SUITE.erl b/lib/stdlib/test/rand_SUITE.erl index 09e1815962..b41941d56b 100644 --- a/lib/stdlib/test/rand_SUITE.erl +++ b/lib/stdlib/test/rand_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2020. All Rights Reserved. +%% Copyright Ericsson AB 2000-2022. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -1090,7 +1090,7 @@ do_measure(_Config) -> end, State) end, - Algs), + Algs ++ [dummy]), _ = measure_1( fun (_) -> 0 end, -- 2.34.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor