Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!enterprise!news0!north!aisaka From: aisaka@cac.co.jp (Aisaka Satoshi) Newsgroups: comp.lang.perl Subject: Re: Slower in numerical calculation than awk? Message-ID: Date: 6 Feb 91 01:05:22 GMT References: <9102040846.AA17752@acf4.NYU.EDU> Sender: news@news0.cac.co.jp Organization: Computer Applications Co., Ltd. Lines: 54 In-reply-to: lixj@acf4.NYU.EDU's message of 4 Feb 91 08:46:53 GMT Hi! I'm Satoshi Aisaka from Japan. In article <9102040846.AA17752@acf4.NYU.EDU> lixj@acf4.NYU.EDU (Xiaojian Li) writes: |I write small awk and perl program, and to my dismay, awk is almost |twice as fast as perl, |---awk--- |#!/bin/awk -f |BEGIN { x = 1.0 | for(i=0;i<100000;++i) x += i |} |END { print x } | |4.99995e+09 |5.6u 0.0s 0:05 100% 0+280k 0+0io 0pf+0w | |---perl--- Both are run on SPARC 1 |#!/usr/local/bin/perl |$X = 1.0; |for ($i = 0; $i < 100000; ++$i) { | $X += $i; |} |print $X, "\n"; | |4999950001 |10.6u 0.1s 0:10 100% 0+428k 0+0io 0pf+0w | |I notice that perl gives more accurate result. Is this higher precision |which causes slowing down? In what precision perls does math? I tried the same test and got different result. My results are: --- awk --- 4.99995e+09 5.3u 0.0s 0:05 99% 20+18k 0+0io 0pf+0w --- perl --- 4999950000 4.7u 0.0s 0:04 99% 46+18k 0+1io 0pf+0w perl is faster than awk on my machine! awk :GNU awk 2.11 (modified for Japanese) perl :Ver3.00 pl.44 (modified for Japanese) machine :SONY NEWS-3860 (with 20MHz R3000,80M real-Memory) -- AISAKA, Satoshi (aisaka%cac.co.jp@uunet.uu.net) R&D for Advanced Technologies, Computer Applications Co., Ltd. 2-3-1 Hitotsubashi Chiyoda-Ku Tokyo 101 Japan Phone (+3)3263-7241 fax(+3)3263-4873