"Fossies" - the Fresh Open Source Software Archive

Member "dmd2/src/druntime/benchmark/gcbench/rand_small.d" (20 Nov 2020, 1053 Bytes) of package /linux/misc/dmd.2.094.2.linux.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) D source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /**
    2  * Benchmark on uniformly distributed, random small allocations.
    3  *
    4  * Copyright: Copyright David Simcha 2011 - 2011.
    5  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
    6  * Authors:   David Simcha
    7  */
    8 
    9 /*          Copyright David Simcha 2011 - 2011.
   10  * Distributed under the Boost Software License, Version 1.0.
   11  *    (See accompanying file LICENSE or copy at
   12  *          http://www.boost.org/LICENSE_1_0.txt)
   13  */
   14 import std.random, core.memory, std.stdio, std.conv;
   15 
   16 void main(string[] args)
   17 {
   18     size_t nIter = 10000;
   19     if(args.length > 1)
   20         nIter = to!size_t(args[1]);
   21 
   22     version (RANDOMIZE)
   23         auto rnd = Random(unpredictableSeed);
   24     else
   25         auto rnd = Random(2929088778);
   26 
   27     auto ptrs = new void*[4096];
   28 
   29     // Allocate large blocks with size uniformly distributed between 8
   30     // and 2048 bytes.
   31     foreach(i; 0..nIter)
   32     {
   33         foreach(ref ptr; ptrs)
   34         {
   35             immutable sz = uniform(8, 2048, rnd);
   36             ptr = GC.malloc(sz, GC.BlkAttr.NO_SCAN);
   37         }
   38     }
   39 }