Python:
#!/usr/bin/env python
import sys, time
def read_file(index,path):
count = 0
with open(path, 'r') as f:
for line in f:
if line not in index:
index[line] = 0
index[line] += 1
count = count + 1
return count
def main():
files_file = sys.argv[1]
index = {}
master_count = 0
st = time.time()
with open (files_file) as f:
for file in f:
path = file[:-1]
print (path)
count = read_file(index,path)
master_count = master_count + count
x = time.time()
elapsed = x - st
rate = int ( float(master_count) / elapsed)
print('Time elapsed: %fs, trx %d rate= %d' % ((x-st), master_count, rate))
if __name__ == '__main__':
main()
Felix:
var index = strdict[int]();
var counter = 0;
var st = time();
var file_file = load (System::argv 1);
for file in split(file_file,"\n") do
println$ file;
for line in split (file.load, "\n") do
index.add line (index.get_dflt (line,0)+1);
++counter;
done
done
var et = time();
var elapsed = et - st;
var trxrate = counter.double / elapsed;
println $ f"Time elapsed: %fs, %d trx, or %.0f trx/sec" (elapsed, counter,
trxrate);
Result: on a small list of files:
Python: Time elapsed: 0.218490s, trx 56426 rate= 258254
Felix: Time elapsed: 1.438417s, 56723 trx, or 39434 trx/sec
Python is about 6 times faster than Felix.
On a larger set of files, Python did well, Felix crashed with
an unknown exception.
Data produced by:
build/release/host/bin/flx_ls . 'src/.*' > files.txt
The unknown exception annoys me greatly.
Especially as:
src/codemirror/theme/3024-night.css
src/codemirror/theme/ambiance-mobile.css
src/codemirror/theme/ambiance.css
Unknown exception in thread!
Program exited normally.
(gdb)
Unknown exceptions are impossible.
Its either a Felix exception (all of which are known) or a C++ standard
library exception (all of which have diagnostic info Felix can decode).
[There was a bug, now fixed, that Felix code wasn't properly wrapped
by exception handler .. clearly it is now. And yes, this code is statically
linked so it isn't the clang dynamic_cast bug. The program also returns
0 which is also wrong]
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language