"Fossies" - the Fresh Open Source Software Archive

Member "dmd2/src/druntime/benchmark/gcbench/slist.d" (20 Nov 2020, 1169 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  * Copyright: Copyright Rainer Schuetze 2014.
    3  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
    4  * Authors:   Rainer Schuetze
    5  *
    6  * This test reads a text file, then splits the result into white space delimited words.
    7  * The result is a single linked list of strings referencing the full text.
    8  * Regarding GC activity, this test probes collection of linked lists.
    9  */
   10 import std.stdio;
   11 import std.conv;
   12 import std.file;
   13 import std.string;
   14 import std.exception;
   15 
   16 struct Node
   17 {
   18     string token;
   19     Node* next;
   20 }
   21 
   22 void main(string[] args)
   23 {
   24     string txt = cast(string) std.file.read(args.length > 1 ? args[1] : "extra-files/dante.txt");
   25     uint cnt = args.length > 2 ? to!uint(args[2]) : 100;
   26     uint allwords = 0;
   27     for(uint i = 0; i < cnt; i++)
   28     {
   29         Node* firstNode;
   30         auto words = txt.split();
   31         foreach(w; words)
   32         {
   33             Node* n = new Node;
   34             n.token = w;
   35             n.next = firstNode;
   36             firstNode = n;
   37         }
   38 
   39         for(Node* p = firstNode; p; p = p.next)
   40             allwords++;
   41     }
   42     enforce(allwords == (args.length > 3 ? to!size_t(args[3]) : 9767600));
   43 }