busfactor1inc / lisp-vs-c-vs-sh Goto Github PK
View Code? Open in Web Editor NEWThis project forked from informatimago/lisp-vs-c
A little comparison of a lisp program vs. a C program vs a POSIX UNIX Shell Script program
This project forked from informatimago/lisp-vs-c
A little comparison of a lisp program vs. a C program vs a POSIX UNIX Shell Script program
Little Comparison Between Common Lisp and C and Shell Script ============================================================ Here is a little program: compute factorial of 42, implemented in C and in Common Lisp and in Shell Script. We note that: 1- the C program runs faster. 2- the C program gives wrong results (who expected differently?). 3- the C program, while being strictly equivalent, counts more parentheses, if you count also the braces, the brackets, the angle-brackets (of #include), and the semi-colon that surround statements… 4- Shell Script is measurably slowest. 5- Shell script has the lowest 'syntax' count (parenthesis and other syntactical structures). Said otherwise: 1- You cannot feel the difference of run-time between the Lisp program and the C program. 2- the Lisp program gives the correct result. 3- the lisp program is more concise and counts fewer parentheses. 4- the shell script program is most concise and counts even fewer parens. ==== fact.c ======= 42! = 0 0.00 real 0.00 user 0.00 sys ==== fact.lisp ==== 42! = 1405006117752879898543142606244511569936384000000000 0.00 real 0.00 user 0.00 sys ==== fact.unix ==== 42! = 1405006117752879898543142606244511569936384000000000 real 0m 0.172s user 0m0.064s sys 0m0.120s =================== fact.lisp 24 parentheses, braces, brackets, angle-brackets, semi-colons, commas fact.c 34 parentheses, braces, brackets, angle-brackets, semi-colons, commas fact.unix 8 parentheses, braces, brackets, angle-brackets, semi-colons, commas ==== fact.lisp ==== (defun fact (x) (if (zerop x) 1 (* x (fact (1- x))))) (defun main () (format t "~%~D! = ~D~%" 42 (fact 42)) (quit 0)) ==== fact.c ==== #include <stdio.h> int fact(int x) { if(0==x) { return(1); } else { return(x*fact(x-1)); } } int main() { printf("\n%d! = %d\n",42,fact(42)); return(0); } =================== ==== fact.unix ==== #!/bin/sh n=42 nf=1 for n in $(seq 1 $n); do nf=$(echo "$nf $n * p" | dc) done echo $nf Note: to compare a more complex and real program implemented in Lisp and in C, have a look at https://github.com/informatimago/scquery (sources/ and sources-cl/). scquery in Lisp 1279 parentheses, braces, brackets, angle-brackets, semi-colons, commas scquery in C 8052 parentheses, braces, brackets, angle-brackets, semi-colons, commas TODO: write scquery in POSIX UNIX.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.