From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,3a6a9f1d654285ba X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!backlog2.nntp.dca.giganews.com!nntp.sun.com!news.sun.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 01 Sep 2009 03:06:16 -0500 Newsgroups: comp.lang.ada Subject: Re: Ada Shootout program for K-Nucleotide (patches) References: <4a743343$0$32674$9b4e6d93@newsspool2.arcor-online.net> <0c18b36c-7af0-454c-8208-9b0416111a1f@w41g2000yqb.googlegroups.com> <4a758ce2$0$31338$9b4e6d93@newsspool4.arcor-online.net> <4a967b33$0$32671$9b4e6d93@newsspool2.arcor-online.net> From: Ole-Hjalmar Kristensen Organization: Sun Microsystems Date: 01 Sep 2009 10:06:15 +0200 Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cache-Post-Path: news1nwk!unknown@khepri42.norway.sun.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-8kGwhj/0HEHDTsrjmIqOO3Ki48rZZ5ZLAEeyNVBzLC8/nLIaEI17XV4lvEBA5Di86H+lKQWrBz09ZjY!e7ZmN9DVsjcG71X8ZjqZJcMwb6TLn+1eV50BlSTpMCaiZOINo6fFOIXU X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 X-Original-Bytes: 3944 Xref: g2news2.google.com comp.lang.ada:8092 Date: 2009-09-01T10:06:15+02:00 List-Id: I see the C++ version uses fgets, which is a reasonably fast way of getting a line. Is there any reason not to use fgets? fgets (OpenSolaris version) uses memccpy to actually copy the buffer until the newline: 43 extern int _filbuf(); 44 extern char *memccpy(); 45 46 char * 47 fgets(ptr, size, iop) 48 char *ptr; 49 register int size; 50 register FILE *iop; 51 { 52 char *p, *ptr0 = ptr; 53 register int n; 54 55 if ( !(iop->_flag & (_IOREAD|_IORW)) ) { 56 iop->_flag |= _IOERR; 57 return (NULL); 58 } 59 60 for (size--; size > 0; size -= n) { 61 if (iop->_cnt <= 0) { /* empty buffer */ 62 if (_filbuf(iop) == EOF) { 63 if (ptr0 == ptr) 64 return (NULL); 65 break; /* no more data */ 66 } 67 iop->_ptr--; 68 iop->_cnt++; 69 } 70 n = MIN(size, iop->_cnt); 71 if ((p = memccpy(ptr, (char *) iop->_ptr, '\n', n)) != NULL) 72 n = p - ptr; 73 ptr += n; 74 iop->_cnt -= n; 75 iop->_ptr += n; 76 _BUFSYNC(iop); 77 if (p != NULL) 78 break; /* found '\n' in buffer */ 79 } 80 *ptr = '\0'; 81 return (ptr0); 82 } >>>>> "GB" == Georg Bauhaus writes: GB> Ole-Hjalmar Kristensen schrieb: >> Character'read could very well be slower if there is no buffering >> involved. The way to read efficiently is to read a large buffer >> (multiple of disk block size) and chop it into lines yourself. >> GB> Indeed, stream attributes won't help. GB> However, replacing Text_IO.Get_Line---which we use now--- GB> might still be considered controversial: GB> - Is "chopping" an acceptable interpretation of "read line by line"? GB> - writing a correct double buffering scheme (or a buffer GB> with end-of-buffer triggers for Read_A_Line_From_Buffer) GB> is still a bit of work, unless there is something we could GB> copy. GB> A package containing a quick getline will definitely be GB> useful in general Unix programming, I should think. GB> What is being used in the Socket packages, BTW? GB> Equally useful will be a package for fast unbounded strings. GB> Replace_Slice is what prevents showcasing GNAT's Spitbol GB> pattern matching as one of the fastest things on this planet! -- C++: The power, elegance and simplicity of a hand grenade.