Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site











SourceForge.net Logo

U++ Core vs D programming language

D programming language authors give a nice example of D language string and map here:

http://www.digitalmars.com/d/2.0/cppstrings.html (Currently unavailable - 2016.08.27)

We have taken the chance to re implement this in U++ and tested with Ubuntu 64 platform. "gdc" compiler was used with flags suggested in the article.

We had to test with larger file than "Alice30.txt", because host platform was too fast for such small file, therefore we combined a couple of text files from the same source to form a single 2MB file.

We have also removed the code to produce the output to make results more relevant.

Results:

 

D language

U++

U++ / D language

0.072s

0.043s

1.7

 

Means C++ is still well ahead of D (by 70%) if not being hold back by standard library design and average implementation...

 

#include <Core/Core.h>

 

using namespace Upp;

 

#define NOOUTPUT

 

int main(int argc, const char *argv[])

{

    int n;

    VectorMap<String, int> map;

    Cout() << "   lines   words   bytes file\n";

    int total_lines = 0;

    int total_words = 0;

    int total_bytes = 0;

    for(int i = 1; i < argc; i++) {

        String f = LoadFile(argv[i]);

        int lines = 0;

        int words = 0;

        const char *q = f;

        for(;;) {

            int c = *q;

            if(IsAlpha(c)) {

                const char *b = q++;

                while(IsAlNum(*q)) q++;

                map.GetAdd(String(b, q), 0)++;

                words++;

            }

            else {

                if(!c) break;

                if(c == '\n')

                    ++lines;

                q++;

            }

        }

        Cout() << Format("%8d%8d%8d %s\n", lines, words, f.GetCount(), argv[i]);

        total_lines += lines;

        total_words += words;

        total_bytes += f.GetCount();

    }

    Vector<int> order = GetSortOrder(map.GetKeys());

#ifndef NOOUTPUT

    Cout() << Format("--------------------------------------%8d%8d%8d total\n", total_lines, total_words, total_bytes);

 

    for(int i = 0; i < order.GetCount(); i++)

        Cout() << map.GetKey(order[i]) << ": " << map[order[i]] << '\n';

#endif

    return 0;

}

 

 

Last edit by klugier on 08/27/2016. Do you want to contribute?. T++