Since it's performance you obviously need to test in your own environment. Several runs give the same results: in-lines is slightly faster with marginally higher gc time. Gives: cpu time: 5046 real time: 5100 gc time: 32Ĭpu time: 4942 real time: 4949 gc time: 36 (call-with-input-file file-path next-line-it)) It's essentially just syntactic sugar for calling read-line in a loop.Įdit: To satisy myself I created a ~500MB text file: #lang racket/base Why do you say in-lines stresses the garbage collector?Ī sequence is not like a list, it's basically a set of procedures that get called repeatedly, one of which returns a value like you mention python yields values. What is going on? What am I doing wrong? What is the proper way of reading a file and processing it line by line? Julia, Lua, MultiLisp, Python, R, Racket, Ruby, Rust, S, Scala, T. The character need not have been read from port, and schemeungetc can be called. Racket includes other compound values besides cons cells. The name lambda comes from the Greek letter as used in the -caluculus, the formal foundation of the Racket language. For 1,000,000 lines, the performance is comparable, in particular file->lines is bit slower and in-lines is faster. Scheme is a dialect of the Lisp family of programming languages. When opening a file for any reason using a name provided from Racket. As we leave Racket behind for our next case study language, ML, bindings really will be immutable. On my computer racket is about 10-15x slower than python for the files with 100 and 10,000 lines. usr/bin/time -p -o awk.dat -a awk '' file.txt > awk.txtįor i in $(seq $n) do echo line $i done > file.txt usr/bin/time -p -o py.dat -a python3 a.py > py.txt usr/bin/time -p -o rkt.dat -a racket a.rkt > rkt.txt read-char reads from the console one character at a. I also added an awk one-liner for comparison: #!/bin/bash write is like display, except that it includes information about the objects representation in the output. Which runs bit faster, but still slow in comparison to python3 #!/usr/bin/python3 So I found another way on stackoverflow (with-input-from-file "file.txt" I'd like to read some files line by line using racket, but my code seems to be slow.īut the code seemed to be slow.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |