⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paper.ps

📁 c programming pearls answer
💻 PS
📖 第 1 页 / 共 5 页
字号:
9 S f
(_ _______________________________________________________________________________________________)1 4311 1 724 3533 t
9 R f
( Solaris)1 -3473(Inferno 1.0)1 401 2 4085 3643 t
(version)763 3753 w
(native)1242 3643 w
(compiler)1242 3753 w
(Bell Labs)1 348 1 1697 3643 t
(1996)1697 3753 w
(Perl 5.003)1 371 1 2173 3643 t
(Perl 5.004)1 371 1 2173 3753 t
(Tcl 7.6)1 256 1 2672 3643 t
(Tk 4.2)1 236 1 2672 3753 t
(Sun)3068 3643 w
(JDK 1.1)1 301 1 3068 3753 t
(MIT)4657 3643 w
(Scheme)4657 3753 w
(7.3)4657 3863 w
9 S f
(_ _______________________________________________________________________________________________)1 4311 1 724 3883 t
9 R f
( Windows)1 -3378(Inferno 1.0)1 401 2 4085 3993 t
(95)763 4103 w
(version)763 4213 w
(Microsoft)1225 3993 w
(Visual)1225 4103 w
(C++ 4.1)1 296 1 1225 4213 t
(Bell Labs)1 348 1 1697 3993 t
(1996)1697 4103 w
( 7.6)1 136( Tcl)1 248(Perl 5.003)1 371 3 2173 3993 t
(Tk 4.2)1 236 1 2672 4103 t
(Sun)3068 3993 w
(JDK 1.1)1 301 1 3068 4103 t
( MIT)1 953(VB 4.0)1 261 2 3608 3993 t
(Scheme)4657 4103 w
(7.4.2)4657 4213 w
9 S f
( \347)1 -4311(_ _______________________________________________________________________________________________)1 4311 2 724 4233 t
(\347)724 4193 w
(\347)724 4103 w
(\347)724 4013 w
(\347)724 3923 w
(\347)724 3833 w
(\347)724 3743 w
(\347)724 3653 w
(\347)724 3563 w
(\347)724 3473 w
(\347)724 3383 w
(\347)724 3293 w
(\347)724 3203 w
(\347)724 3113 w
(\347)724 3023 w
(\347)724 2933 w
(\347)724 2843 w
(\347)724 2753 w
(\347)724 2663 w
(\347)1166 4233 w
(\347)1166 4193 w
(\347)1166 4103 w
(\347)1166 4013 w
(\347)1166 3923 w
(\347)1166 3833 w
(\347)1166 3743 w
(\347)1166 3653 w
(\347)1166 3563 w
(\347)1166 3473 w
(\347)1166 3383 w
(\347)1166 3293 w
(\347)1166 3203 w
(\347)1166 3113 w
(\347)1166 3023 w
(\347)1166 2933 w
(\347)1166 2843 w
(\347)1166 2753 w
(\347)1166 2663 w
(\347)5035 4233 w
(\347)5035 4193 w
(\347)5035 4103 w
(\347)5035 4013 w
(\347)5035 3923 w
(\347)5035 3833 w
(\347)5035 3743 w
(\347)5035 3653 w
(\347)5035 3563 w
(\347)5035 3473 w
(\347)5035 3383 w
(\347)5035 3293 w
(\347)5035 3203 w
(\347)5035 3113 w
(\347)5035 3023 w
(\347)5035 2933 w
(\347)5035 2843 w
(\347)5035 2753 w
(\347)5035 2663 w
9 R f
(\(1\) Embeddings of Tk for Perl and Scheme appear to be experimental and unsupported; we did not try them.)18 3912 1 789 4453 t
10 B f
( Characteristics)1 673( Language)1 473(Table 1:)1 353 3 2130 4628 t
(C)720 4904 w
10 R f
( for using an interpreted)4 967(is included as a baseline: its performance suggests the size of the runtime penalty)13 3255 2 818 4904 t
( operations and auto-)3 861( is the only one of the eight languages that does not have built-in string)14 2949(language. C)1 510 3 720 5024 t
(matic garbage collection.)2 1006 1 720 5144 t
10 B f
(Awk)720 5300 w
10 R f
(and)946 5300 w
10 B f
(Perl)1116 5300 w
10 R f
( and numbers are the only)5 1044( Strings)1 336( Perl has many more features.)5 1196(are similar in style, although)4 1145 4 1319 5300 t
( Awk\); both are normally inter-)5 1301(data types; associative arrays are the main data structure \(the only one in)12 3019 2 720 5420 t
( of the authors admits to a paternal interest in Awk.)10 2050(preted. One)1 490 2 720 5540 t
10 B f
(Tcl)720 5696 w
10 R f
( the Unix C shell; besides strings, it provides associative arrays.)10 2578(is an interpreter reminiscent of)4 1233 2 886 5696 t
10 B f
(Tk)4750 5696 w
10 R f
(is a)1 139 1 4901 5696 t
( through a ``windowing shell'' called)5 1544(user interface toolkit normally packaged to be run from Tcl scripts)10 2776 2 720 5816 t
( 7.6 is a pure interpreter; the more recent Tcl 8.0 includes an on-the-fly bytecode compiler.)15 3625(Wish. Tcl)1 419 2 720 5936 t
10 B f
(Java)720 6092 w
10 R f
( with a standard user interface library, the Abstract Window)9 2448( comes)1 285( Java)1 232(is derived from C and C++.)5 1125 4 950 6092 t
( a Web)2 322( programs can be run standalone or as ``applets'' invoked from within)11 3028( Java)1 248(Toolkit or AWT.)2 722 4 720 6212 t
(browser; in either case, the intermediate representation may be interpreted, or it may be compiled just-in-)15 4320 1 720 6332 t
(time for the machine on which the program is being run.)10 2255 1 720 6452 t
10 B f
(Visual Basic)1 529 1 720 6608 t
10 R f
( interpreter loosely in the same class as Java. It provides an especially easy environment)14 3574(is an)1 189 2 1277 6608 t
( Basic is available only for Windows 95 and NT.)9 1953( Visual)1 311(for creating graphical interfaces.)3 1295 3 720 6728 t
10 B f
(Limbo)720 6884 w
10 R f
( domain with)2 550(is a language in the same general class as Java and attacks much the same problem)15 3451 2 1039 6884 t
( is part of Inferno, a virtual operating)7 1543( Limbo)1 326( normally interpreted.)2 886(somewhat the same facilities; it too is)6 1565 4 720 7004 t
( has its own)3 502( Limbo)1 326( on Windows 95 and NT and many flavors of Unix.)10 2151(system that runs)2 666 4 720 7124 t
10 I f
(ab initio)1 346 1 4399 7124 t
10 R f
(imple-)4779 7124 w
( to personal and corporate interests in)6 1539( authors admit)2 588( The)1 213(mentation of Tk for writing graphical interfaces.)6 1980 4 720 7244 t
cleartomark
showpage
saveobj restore
end
%%PageBoundingBox: 61 52 514 764
%%EndPage: 3 3
%%Page: 4 4
%%PageBoundingBox: (atend)
DpostDict begin
/saveobj save def
mark
4 pagesetup
10 R f
(- 4 -)2 166 1 2797 480 t
(Limbo.)720 840 w
10 B f
(Scheme)720 996 w
10 R f
( tested the MIT Scheme versions)5 1372( We)1 200(is a functional language extended by assignment and I/O.)8 2384 3 1084 996 t
( Scheme com-)2 579( tried several)2 525( We)1 193(shown in Table 1, both of which are pure interpreters that date from 1993.)13 3023 4 720 1116 t
( VSCM, and Edscheme, but each failed to)7 1685(pilers that are accessible on the Web, including Scheme48, Stalin,)9 2635 2 720 1236 t
( [Clinger)1 361( \(See)1 230( of our test programs or was not readily available for all of our computing platforms.)15 3423(run one)1 306 4 720 1356 t
(97] for more Scheme comparisons.\))4 1433 1 720 1476 t
( languages like Unix shells, Python and)6 1634(Given more time and energy, one might test other scripting)9 2436 2 970 1632 t
(REXX, functional languages like SML, and interface-building languages like Delphi.)9 3412 1 720 1752 t
10 B f
(Choice of Machines)2 838 1 720 1992 t
10 R f
(We ran our tests on three machines:)6 1430 1 970 2148 t
10 S f
(\267)1020 2304 w
10 R f
(100 MHz MIPS R4000 SGI Indy, Irix 5.3)7 1669 1 1116 2304 t
10 S f
(\267)1020 2460 w
10 R f
(50 MHz Sun Sparcstation-10, Solaris 2.5 \(SunOS 5.5\))7 2166 1 1116 2460 t
10 S f
(\267)1020 2616 w
10 R f
( This)1 230( 95.)1 152(100 MHz Pentium \(32Mb Micron Millennia, Diamond Stealth64 2001 video\), Windows)10 3542 3 1116 2616 t
(PC appears to be identical to the one used for tests in [Booth 97].)13 2603 1 970 2736 t
( the further advantage that)4 1067( us, they offered)3 660( For)1 193(Although elderly, these machines are very similar in speed.)8 2400 4 720 2892 t
( that no one else was using them during our tests, which removed one source of variability.)16 3666(we could ensure)2 654 2 720 3012 t
( test on each system, except for Visual Basic, which we ran only on the PC, and Java,)17 3516(We could run every)3 804 2 720 3132 t
( where noted, we used the same implementa-)7 1817( Except)1 331(for which we did not have an implementation on Irix.)9 2172 3 720 3252 t
(tions across systems.)2 836 1 720 3372 t
10 B f
(Gathering Timing Statistics)2 1184 1 720 3612 t
10 R f
( encoun-)1 350( We)1 192(The difficulty of measuring program runtimes reliably and reproducibly is well known.)11 3528 3 970 3768 t
(tered the following obstacles, among others:)5 1770 1 720 3888 t
( erratic as a time-shared machine becomes more heavily used.)9 2498(- Runtime measurements become more)4 1572 2 970 4044 t
( the middle of a test, with)6 1043(Even on single-user machines, system processes can spring into activity in)10 3027 2 970 4164 t
( timings on PC's are notoriously unreliable, especially for)8 2344( Process)1 359(unpredictable effects on runtimes.)3 1367 3 970 4284 t
( be much greater than the)5 1051( clock times can)3 673( Wall)1 253(short runs, but they are no better on Unix systems.)9 2093 4 970 4404 t
(sum of system and user times, even on apparently quiescent systems.)10 2758 1 970 4524 t
( file)1 168(- I/O times can be badly misleading when the computer is far from the file, as with networked)17 3902 2 970 4680 t
( from the)2 368( for graphics operations can be badly misleading when the display is remote)12 3058(systems. Times)1 644 3 970 4800 t
(computer, as with X terminals.)4 1232 1 970 4920 t
( Some-)1 321( the more often they are run, as if they get better with practice.)13 2621(- Some programs run faster)4 1128 3 970 5076 t
( reads a big file may run faster on the second)10 1800(times this is due to caching; for example, a program that)10 2270 2 970 5196 t
(and subsequent runs because the program and the file are already in memory.)12 3084 1 970 5316 t
( suspect that the increasing run-)5 1282( We)1 191(- A few programs take longer to run the more often they are run.)13 2597 3 970 5472 t
(time is due to memory management problems.)6 1857 1 970 5592 t
( of ``user time'' and ``system time'' reported by the)9 2187(Times for C, Awk, Perl, and Tcl are the sum)9 1883 2 970 5748 t
10 CW f
(time)720 5868 w
10 R f
(command on Unix, or the total time reported by the MKS Toolkit)11 2665 1 989 5868 t
10 CW f
(time)3683 5868 w
10 R f
( 95.)1 153(command on Windows)2 935 2 3952 5868 t
( include the time to invoke the language processor \(for Awk, Perl, and Tcl\) or to load and start)18 3861(Thus, these)1 459 2 720 5988 t
(the program \(for C\) as well as to read, process and execute the programs.)13 2917 1 720 6108 t
( Basic, and Limbo are computed by the internal program timer, such as)12 2888(Times for Java, Visual)3 913 2 970 6264 t
10 CW f
(Date)4800 6264 w
10 R f
(in Java and)2 475 1 720 6384 t
10 CW f
(Timer)1233 6384 w
10 R f
( For)1 201( exclude all startup times, which can amount to several seconds.)10 2687( These)1 301(in VB.)1 280 4 1571 6384 t
( startup delay, presumably from unpacking the standard)7 2280(example, the Java interpreter exhibits a noticeable)6 2040 2 720 6504 t
(class files.)1 416 1 720 6624 t
( internal timing function in MIT Scheme,)6 1862( The)1 240( challenge.)1 467(Timing Scheme programs posed a)4 1501 4 970 6780 t
10 CW f
(runtime)720 6900 w
10 R f
( \(The)1 246(, reports values that are only loosely correlated with wall-clock time.)10 2835 2 1140 6900 t
10 CW f
(runtime)4254 6900 w
10 R f
(function)4707 6900 w
( in the Scheme reference)4 1033(appears in the standard Scheme text [Abelson 96], although it is not mentioned)12 3287 2 720 7020 t
( Irix and Windows,)3 795( On)1 180([Scheme 91].\))1 573 3 720 7140 t
10 CW f
(runtime)2301 7140 w
10 R f
( On)1 179(reports values that are too low by 10 to 25 percent.)10 2107 2 2754 7140 t
(Solaris,)720 7260 w
10 CW f
(runtime)1051 7260 w
10 R f
( we used a stopwatch)4 864( Consequently,)1 629( percent.)1 347(reports times that are too high by 30 to 65)9 1701 4 1499 7260 t
cleartomark
showpage
saveobj restore
end
%%PageBoundingBox: 61 50 514 764
%%EndPage: 4 4
%%Page: 5 5
%%PageBoundingBox: (atend)
DpostDict begin
/saveobj save def
mark
5 pagesetup
10 R f
(- 5 -)2 166 1 2797 480 t
( Scheme times also exclude the interpreter startup time.)8 2216( The)1 205(to record Scheme times.)3 965 3 720 840 t
(To gather the timings, we ran each test several times, usually with a loop like this:)15 3283 1 970 996 t
9 CW f
(for i in 1 2 3 4 5 6 7 8 9 10)12 1566 1 1440 1166 t
(do time)1 378 1 1656 1276 t
9 I f
(commandline)2088 1276 w
9 CW f
(done)1440 1386 w
10 R f
( the runtime was more than a minute or)8 1586( If)1 118( for caching.)2 505(We discarded the first time to compensate \(partially\))7 2111 4 720 1566 t
(so, we normally ran the test only 2 or 3 times: when one version of a program runs in a few seconds, but)22 4320 1 720 1686 t
( times measured)2 659( For)1 194( latter time with pinpoint accuracy.)5 1423(another takes minutes, there is no reason to fix the)9 2044 4 720 1806 t
( accompanying the graphs explain unusual situ-)6 1915( Notes)1 285( ran between 5 and 10 trials.)6 1140(in seconds, we normally)3 980 4 720 1926 t
(ations, such as large variability in the runtimes.)7 1890 1 720 2046 t
10 B f
( of Basic Features)3 757(2. Tests)1 347 2 720 2286 t
10 R f
(The first tests exercise basic language features like arithmetic, loops and function calls.)12 3482 1 970 2442 t
10 B f
(Loops and arithmetic)2 917 1 720 2682 t
10 R f
( of loop mechanisms by counting to)6 1457(First we test the implementation overhead)5 1694 2 970 2838 t
10 CW f
(n)4150 2838 w
10 R f
( large values)2 512(. Using)1 318 2 4210 2838 t
(of)720 2958 w
10 CW f
(n)836 2958 w
10 R f
( that runtime is linear in the value of)8 1518( Verifying)1 446(helps to reduce noise in the timing measurements.)7 2054 3 929 2958 t
10 CW f
(n)4980 2958 w
10 R f
(helps to detect ambitious optimizers \(see below\).)6 1956 1 720 3078 t
( example, here is the C version:)6 1262( For)1 189(Programs in most of the languages look similar.)7 1916 3 970 3234 t
9 CW f
(int i, n = atoi\(argv[1]\), sum = 0;)7 1836 1 1008 3404 t
(for \(i = 0; i < n; i++\))7 1242 1 1008 3514 t
(sum++;)1440 3624 w
10 R f
(and the Tcl version:)3 796 1 720 3804 t
9 CW f
(set sum 0)2 486 1 1008 3974 t
(set n [lindex $argv 0])4 1188 1 1008 4084 t
(for {set i 0} {$i < $n} {incr i} {)9 1836 1 1008 4194 t
(incr sum)1 432 1 1440 4304 t
(})1008 4414 w
10 R f
( Scheme version of the program, which is conventional in its use of tail-recursion to)14 3368(We timed the following)3 952 2 720 4594 t
(implement the loop, but unusual in using)6 1637 1 720 4714 t
10 CW f
(set!)2382 4714 w
10 R f
(to modify a global variable repeatedly:)5 1550 1 2672 4714 t
9 CW f
(\(define sum 0\))2 756 1 1008 4884 t
(\(define \(tail-rec-aux i n\))3 1404 1 1008 4994 t
(\(if \(< i n\))3 594 1 1440 5104 t
(\(begin \(set! sum \(+ sum 1\)\) \(tail-rec-aux \(+ i 1\) n\)\))10 2862 1 1872 5214 t
(sum\)\))1872 5324 w
(\(define \(tail-rec-loop n\))2 1350 1 1008 5434 t
(\(tail-rec-aux 0 n\)\))2 1026 1 1440 5544 t
10 R f
(An alternative version that passes three arguments to)7 2145 1 720 5724 t
10 CW f
(tail-rec-aux)2895 5724 w
10 R f
(and only uses)2 554 1 3645 5724 t
10 CW f
(set!)4230 5724 w
10 R f
(at the end of)3 514 1 4526 5724 t
(the recursion runs about five percent faster.)6 1731 1 720 5844 t
( \()1 64(For unreconstructed imperative-style programmers, Scheme defines an iteration construct)8 3619 2 970 6000 t
10 CW f
(do)4653 6000 w
10 R f
(\), with)1 267 1 4773 6000 t
(which the loop above could be written as follows:)8 1992 1 720 6120 t
9 CW f
(\(define sum 0\))2 756 1 1008 6290 t
(\(define \(do-loop n\))2 1026 1 1008 6400 t
(\(do \(\(i 0 \(+ i 1\)\)\))5 1026 1 1440 6510 t
(\(\(>= i n\) sum\))3 756 1 1872 6620 t
(\(set! sum \(+ sum 1\)\)\)\))4 1188 1 1872 6730 t
10 R f
( With)1 277( same as for the tail-recursive version.)6 1683(With MIT Scheme, the runtime for this version is the)9 2360 3 720 6910 t
(Edscheme, a commercial PC implementation, the)5 2028 1 720 7030 t
10 CW f
(do)2784 7030 w
10 R f
( tail-recursive form.)2 815(version ran twice as fast as the)6 1285 2 2940 7030 t
( we finished)2 508(We could not do more experiments with Edscheme since our evaluation copy expired before)13 3812 2 720 7150 t
(our tests.)1 361 1 720 7270 t
cleartomark
showpage
saveobj restore
end
%%PageBoundingBox: 61 49 514 764
%%EndPage: 5 5
%%Page: 6 6
%%PageBoundingBox: (atend)
DpostDict begin
/saveobj save def
mark
6 pagesetup
10 R f
(- 6 -)2 166 1 2797 480 t
2280 2466 1200 2466 Dl
1200 1026 1200 2466 Dl
(Irix)1668 961 w
10 CW f
(n)1449 2786 w
10 R f
(\(in millions\))1 498 1 1534 2786 t
1304 2502 1304 2466 Dl
(0.125)1192 2612 w
1630 2502 1630 2466 Dl
(0.25)1543 2612 w
1954 2502 1954 2466 Dl
(0.5)1892 2612 w
2280 2502 2280 2466 Dl
(1)2255 2612 w
(seconds)729 1766 w
1164 2131 1200 2131 Dl
(0.1)1014 2151 w
1164 1796 1200 1796 Dl
(1)1089 1816 w
1164 1461 1200 1461 Dl
(10)1039 1481 w
1164 1126 1200 1126 Dl
(100)989 1146 w
7 S1 f
()1291 2326 w
7 S1 f
1291 2326 m
27 build_ob
1318 2326 m
()1617 2284 w
1617 2284 m
27 build_ob
1644 2284 m
7 R f
(.)1294 2309 w
(.)1330 2304 w
(.)1366 2299 w
(.)1403 2295 w
(.)1439 2290 w
(.)1475 2286 w
(.)1511 2281 w
(.)1547 2276 w
(.)1583 2271 w
(.)1620 2267 w
7 S1 f
()1941 2203 w
1941 2203 m
27 build_ob
1968 2203 m
7 R f
(.)1620 2267 w
(.)1656 2258 w
(.)1692 2249 w
(.)1728 2240 w
(.)1764 2231 w
(.)1800 2222 w
(.)1836 2213 w
(.)1872 2204 w
(.)1908 2195 w
(.)1944 2186 w
7 S1 f
()2267 2113 w
2267 2113 m
27 build_ob
2294 2113 m
7 R f
(.)1944 2186 w
(.)1980 2175 w
(.)2016 2165 w
(.)2053 2155 w
(.)2089 2145 w
(.)2125 2136 w
(.)2161 2126 w
(.)2197 2116 w
(.)2233 2106 w
(.)2270 2096 w
8 R f
(C)2320 2113 w
7 S1 f
()1291 1701 w
1291 1701 m
27 build_ob
1318 1701 m
()1617 1601 w
1617 1601 m
27 build_ob
1644 1601 m
7 R f
(.)1294 1684 w
(.)1330 1673 w
(.)1366 1662 w
(.)1403 1651 w
(.)1439 1640 w
(.)1475 1628 w
(.)1511 1617 w
(.)1547 1606 w
(.)1583 1594 w
(.)1620 1584 w
7 S1 f
()1941 1501 w
1941 1501 m
27 build_ob
1968 1501 m
7 R f
(.)1620 1584 w
(.)1656 1572 w
(.)1692 1561 w
(.)1728 1551 w
(.)1764 1540 w
(.)1800 1528 w
(.)1836 1517 w
(.)1872 1507 w
(.)1908 1495 w
(.)1944 1484 w
7 S1 f
()2267 1404 w
2267 1404 m
27 build_ob
2294 1404 m
7 R f
(.)1944 1484 w
(.)1980 1473 w
(.)2016 1463 w
(.)2053 1452 w
(.)2089 1441 w
(.)2125 1430 w
(.)2161 1419 w
(.)2197 1409 w
(.)2233 1398 w
(.)2270 1387 w
8 R f
(Awk)2320 1404 w
7 S1 f
()1291 1789 w
1291 1789 m
27 build_ob
1318 1789 m
()1617 1695 w
1617 1695 m
27 build_ob
1644 1695 m
7 R f
(.)1294 1772 w
(.)1330 1762 w
(.)1366 1751 w
(.)1403 1741 w
(.)1439 1731 w
(.)1475 1720 w
(.)1511 1710 w
(.)1547 1699 w
(.)1583 1688 w
(.)1620 1678 w
7 S1 f
()1941 1597 w
1941 1597 m
27 build_ob
1968 1597 m
7 R f
(.)1620 1678 w
(.)1656 1667 w
(.)1692 1656 w
(.)1728 1646 w
(.)1764 1635 w
(.)1800 1623 w
(.)1836 1612 w
(.)1872 1602 w
(.)1908 1591 w
(.)1944 1580 w

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -