Unfortunately, the binary has been stripped out by the list software.

I suspect the C program will be slower than my Rebol script, because the C
program reads the file twice, where my Rebol script only reads the file
once. Disk I/O is usually the slowest part of any algorithm.

Andrew Martin
ICQ: 26227169 http://valley.150m.com/
-><-

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, September 07, 2002 2:53 PM
Subject: [REBOL] Re: Sort by first part of line


>
>
>
> -- Attached file included as plaintext by Listar --
>
> That sounds like a fast machine you have Andrew.
>
> I would like for you to run a test if you would.
>
> SOURCE CODE of what I am sending:
> /* QSORT.C: This program reads the name of a file
>  *   to be sorted, from the command line. The lines
>  *   are read into memory then sorted and then written
>  *   to stdout.
>  *
>  * Note: The sort is of the entire ASCII line and does
>  *   not parse the line in any way.
>  *
>  * Sample:
>   *  qsort sortme.txt > sorted.txt
>  */
>
> #include <stdlib.h>
> #include <string.h>
> #include <stdio.h>
> #include <time.h>
>
> #define MAX_LINE_SIZE 1024
>
> int compare( const void *arg1, const void *arg2 );
>
> char line[MAX_LINE_SIZE];
> char ** lines;
> int lcnt = 0;
> FILE * stream = NULL;
> time_t  start, finish;
> double  elapsed_time;
>
>
> void CountTheLines(char *);
> void ReadTheLines(char *);
> void SortTheLines(void);
> void OutputTheLines(void);
>
> void main( int argc, char **argv )
> {
> if (argc != 2)
> {
> printf("Usage: %s nameoffiletosort\n", argv[0]);
> exit(1);
> }
>
> time( &start );
> CountTheLines(argv[1]);
> ReadTheLines(argv[1]);
> SortTheLines();
> OutputTheLines();
> time( &finish );
> elapsed_time = difftime( finish, start );
> printf( "\nSorted %d lines in %6.0f seconds.\n", lcnt, elapsed_time );
> }
>
> void CountTheLines(char *fn)
> {
> // Count the lines in the file
> stream = fopen(fn, "r");
> if(stream == NULL)
> {
> printf( "Unable to open input file\n" );
> exit(1);
> }
> while (fgets(line, MAX_LINE_SIZE, stream) != NULL)
> lcnt++;
> fclose(stream);
>
> // Allocate a place to put the lines
> lines = (char **)malloc(lcnt*sizeof(char *));
> }
>
> void ReadTheLines(char *fn)
> {
> // Read lines into memory
> lcnt = 0;
>
> stream = fopen(fn, "r");
> if(stream == NULL)
> {
> printf( "Unable to open input file\n" );
> exit(1);
> }
> while (fgets(line, MAX_LINE_SIZE, stream) != NULL)
> lines[lcnt++] = strdup(line);
> fclose(stream);
> }
>
> void SortTheLines()
> {
> // Sort the lines
> qsort( (void *)lines, (size_t)lcnt, sizeof( char * ), compare );
> }
>
> void OutputTheLines()
> {
> int i;
>
> // Output the sorted lines
> for( i = 0; i < lcnt; ++i )
> printf( "%s", lines[i] );
> }
>
> int compare( const void *arg1, const void *arg2 )
> {
> /* Compare all of both strings: */
> return _stricmp( * ( char** ) arg1, * ( char** ) arg2 );
> }
>
>
> Download NeoPlanet at http://www.neoplanet.com
>
>
> -- Binary/unsupported file stripped by Listar --
> -- Type: Application/Octet-Stream
>
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to