Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Efficient processing of large nuumeric data file
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bearophileh...@lycos.com  
View profile  
 More options Jan 18 2008, 7:59 pm
Newsgroups: comp.lang.python
From: bearophileH...@lycos.com
Date: Fri, 18 Jan 2008 16:59:34 -0800 (PST)
Local: Fri, Jan 18 2008 7:59 pm
Subject: Re: Efficient processing of large nuumeric data file
...and just for fun this D code is about 3.2 times faster than the
Psyco version for the same dataset (30% lines with a space):

import std.stdio, std.conv, std.string, std.stream;

int[int] get_hist(string file_name) {
    int[int] hist;

    foreach(string line; new BufferedFile(file_name)) {
        int pos = find(line, ' ');
        if (pos == -1)
            hist[toInt(line)]++;
        else
            hist[toInt(line[0 .. pos])] += toInt(line[pos+1 .. $]);
    }

    return hist;

}

void main(string[] args) {
    writefln( get_hist(args[1]).length );

}

Bye,
bearophile

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.