"Fossies" - the Fresh Open Source Software Archive

Member "dmd2/src/druntime/benchmark/gcbench/conalloc.d" (20 Nov 2020, 1341 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  * The goal of this program is to do very CPU intensive work with allocations in threads
    3  *
    4  * Copyright: Copyright Leandro Lucarella 2014.
    5  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
    6  * Authors:   Leandro Lucarella
    7  */
    8 import core.thread;
    9 import core.atomic;
   10 import std.conv;
   11 import std.file;
   12 import std.digest.sha;
   13 
   14 __gshared int N = 2500;
   15 __gshared int NT = 4;
   16 
   17 __gshared ubyte[] BYTES;
   18 shared(int) running; // Atomic
   19 
   20 void main(string[] args)
   21 {
   22     auto fname = "extra-files/dante.txt";
   23     if (args.length > 3)
   24         fname = args[3];
   25     if (args.length > 2)
   26         NT = to!int(args[2]);
   27     if (args.length > 1)
   28         N = to!int(args[1]);
   29     N /= NT;
   30 
   31     atomicStore(running, NT);
   32     BYTES = cast(ubyte[]) std.file.read(fname);
   33     auto threads = new Thread[NT];
   34     foreach(ref thread; threads)
   35     {
   36         thread = new Thread(&doSha);
   37         thread.start();
   38     }
   39     while (atomicLoad(running))
   40     {
   41         auto a = new ubyte[](BYTES.length);
   42         a[] = cast(ubyte[]) BYTES[];
   43         Thread.yield();
   44     }
   45     foreach(thread; threads)
   46         thread.join();
   47 }
   48 
   49 void doSha()
   50 {
   51     for (size_t i = 0; i < N; i++)
   52     {
   53         auto sha = new SHA1; // undefined identifier SHA512?
   54         sha.put(BYTES);
   55     }
   56     import core.atomic : atomicOp;
   57     atomicOp!"-="(running, 1);
   58 }