Example of using tables - Printable Version +- NaaLaa (https://www.naalaa.com/forum) +-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html) +--- Forum: NaaLaa 7 Code (https://www.naalaa.com/forum/forum-4.html) +--- Thread: Example of using tables (/thread-72.html) |
Example of using tables - Tomaaz - 02-09-2024 Again, it's not the type of program NaaLaa has been designed for, but it's one from my long list of simple programs I test every single language I try with. Some the members here may remember the word count challenge we had on basicprogramming.org. N6 was pretty useless at this task, but N7 is a completely different beast. I was impressed by how easy (thanx to tables, the split function and the free val procedure) was to write this program, considering the fact that NaaLaa doesn't have sorting algorithms built-in. The task is to read a text file, remove all non-word characters, count all words, count unique words, count how many times each word appears in the text, sort the words by occurrence an save the result to the file. And here is the code: Code: open file 1, "Hamlet.txt" OK. And now let's move to graphics and games. I won't bore you with this kind of programs, anymore. RE: Example of using tables - 1micha.elok - 02-12-2024 There are 32.052 words in the "Hamlet.txt" Part 1.Processing text file in 73.766 seconds Part 2.Writing on text file (Words.txt) 0.019 seconds RE: Example of using tables - johnno56 - 02-12-2024 All words - 32052 Part 1: 33.598 Part 2: 0.012 RE: Example of using tables - Tomaaz - 02-12-2024 And this version? Code: unwanted_characters = [] Should be around 3-4 times faster. What's interesting is that the old version takes around 30 sec. on my laptop. How is it possible? My laptop is pretty old and slow, so how come it is faster than your machines??? The new one takes 8 sec., btw. RE: Example of using tables - 1micha.elok - 02-13-2024 The second version ------------------------------------------- Reading the file in 15.81 seconds Counting in 0.033 seconds Saving the result in 0.034 seconds -------------------------------------------- It's faster than the first version Tested on : - Intel Core i5-6200U CPU @2.30GHz - RAM 4.00 GB - Windows 7 64 bit RE: Example of using tables - johnno56 - 02-13-2024 So much quicker.... Cool... Thank Tomaaz! Read file in : 7.262 secs. Counted in : 0.023 secs. Saved file in : 0.018 secs. AMD Ryzen 5 5600G @ 3.9Ghz RAM 16 GB 64 bit Linux Mint 21.2 RE: Example of using tables - Tomaaz - 02-13-2024 johnno56, 1micha.elok could you test the sped of this version? Code: unwanted_characters = [] Thanx! RE: Example of using tables - johnno56 - 02-13-2024 Wow! What are you feeding that program of yours? All words - 32051 Unique words - 4595 Reading: 0.175 secs. Counting: 0.022 secs. Writing: 0.017 secs. RE: Example of using tables - Tomaaz - 02-13-2024 Well, some could say I'm cheating a little bit in the last example, but I would happily disagree. The main difference is that the file is read by the system function, but the whole text processing, counting, sorting and saving is done by NaaLaa. It would be rather easy to add a function that can read entire text file to NaaLaa and the result would be more or less the same. The only reason NaaLaa doesn't have a function like that is the fact that it doesn't really need it. Anyway, less than one second? That's impressive. RE: Example of using tables - 1micha.elok - 02-15-2024 It's a quantum leap --------------------------------------------------- Processing / Reading the file in 1st version 73.766 seconds 2nd version 15.81 seconds 3rd version 0.58 seconds ---------------------------------------------------- Tested on : - Intel Core i5-6200U CPU @2.30GHz - RAM 4.00 GB - Windows 7 64 bit ---------------------------------------------------- |