Compiled or interpreted

Chat about just about anything else
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 30 days after creation.
Locked
User avatar
AndyMH
Level 21
Level 21
Posts: 13728
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Compiled or interpreted

Post by AndyMH »

I'm having a lot of fun at the moment playing around with IoT, specifically arduino. It's meant learning C++ and now javascript & html (the language I'm most comfortable with is pascal - use lazarus). I'm building a weather station running on a nodeMCU. It FTPs csv files to my NAS daily and also has a web interface (below). The balloons will be replaced with graphs showing temperature and pressure over the last 24 hrs. These are generated using google charts.

At the moment the nodeMCU feeds the browser with a csv file which is running javascript to parse into the format required by google charts. My question - which would be quicker:
  • Parsing the data on the nodeMCU (running at 70MHz) using compiled code to feed the browser with either an object or array, or
  • Doing what I'm doing at the moment - feeding the browser with a csv file, parsed with javascript (interpreted) but running on a laptop at around 2GHz?
Weather - Chromium_008.jpg
PS - like playing with computers? I can recommend this, an easy route to spending hours and hours :D
Last edited by LockBot on Wed Dec 07, 2022 4:01 am, edited 2 times in total.
Reason: Topic automatically closed 30 days after creation. New replies are no longer allowed.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: Compiled or interpreted

Post by xenopeek »

It's possible to write slow code with compiled languages and fast code with interpreted languages. That said a 2 GHz multi core processor has more than 30 times as much headroom as a 70 MHz processor before it would be impacted by badly optimized code. Whether your code is interpreted or compiled is a minor aspect of performance.

How big is the CSV file? Papa Parse (Javascript library for parsing CSV files) says it can load a 1 GiB file in 20 seconds. Work back from that if you should have worries about browser performance.

An approach I might take is collect the data in a JSON file, or transform collected data periodically to JSON format, and have the Javascript code fetch the JSON files and use those to build the structure that your charts library needs?
Image
gm10

Re: Compiled or interpreted

Post by gm10 »

AndyMH wrote: Sun Feb 10, 2019 10:33 am My question - which would be quicker:
  • Parsing the data on the nodeMCU (running at 70MHz) using compiled code to feed the browser with either an object or array, or
  • Doing what I'm doing at the moment - feeding the browser with a csv file, parsed with javascript (interpreted) but running on a laptop at around 2GHz?
Unless I'm misunderstanding, you are only asking what format the nodeMCU should provide the data in? In other words, the page rendering, google charts etc., will always happen on the client, right? So I'd say that it doesn't matter one bit. The browser would possibly interpret json a bit faster than it may take your js to parse the csv, but unless your js sucks it's probably milliseconds at best and not even relevant compared to the cost of loading the google charts module and rendering the page.

The only way to really save time on the browser would be to off-load the charting to the arduino. It would be much slower to do there but I don't think for this type of data the delay matters. I do however also not think the rendering cost on your laptop matters. So either way is fine. ;)

Looks nice by the way.
Hoser Rob
Level 20
Level 20
Posts: 11796
Joined: Sat Dec 15, 2012 8:57 am

Re: Compiled or interpreted

Post by Hoser Rob »

Interpreters were definitely noticeably slower than compiled programs in, say, 1982 or so. I'm not so sure you'd notice the difference nowadays.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: Compiled or interpreted

Post by xenopeek »

Interpreted languages can use a "just in time" compiler to optimize speed of frequently executed code (like inside loops). This article gives a good overview: https://hacks.mozilla.org/2017/02/a-cra ... compilers/. Javascript uses that. CSV parsing code would be a good example of something that will get compiled even with an interpreted language.

Like gm10 said, if you have a CSV file with hundreds or even thousands of records it will be parsed in milliseconds. The Papa Parse library parses about 55KiB of CSV data per millisecond. Can you do it faster with a compiled language if you known what you're doing? Sure, but not if that code is run on the nodeMCU :)

If you want faster speed in the browser you can look at WebAssembly (wasm), a platform independent binary format alternative to Javascript scripts. Makes downloads smaller, forgoes need for parsing or JIT compiling and can be optimized at compile time. Programming languages like C and Rust can target wasm with their compilers. Unless the CSV files are tens of megabytes it won't make a difference to the user.
Image
User avatar
AndyMH
Level 21
Level 21
Posts: 13728
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Compiled or interpreted

Post by AndyMH »

Thanks for the responses.

Yep. It was about what format the nodeMCU should serve, rendering will always happen on the client and I don't even want to think about trying to do google charts on the nodeMCU, if at all possible.
Interpreters were definitely noticeably slower than compiled programs in, say, 1982 or so
I'm of that vintage (or older :( ) hence the question and the trade 70MHz compiled vs 2GHz interpreted.

CSV files are small, date/time, temp, pressure, humidity, dewpoint every 30 mins for 24 hrs < 2kb.

Did have a brief look at papa parse, I'm using jQuery-CSV.

And yes, the gauges look nice, but nothing original - https://canvas-gauges.com/ and very easy to use.

I'll stick with what I'm doing since I've already done most of it, but will have a look at WebAssembly.

Must admit that I keep tripping up with syntax, assignment: pascal :=, c++/javascript =, code blocks: pascal begin/end, c++/javascript {}, comparison: pascal = c++ == javascript == or ===, and so on. So I make silly errors. I like the lazarus IDE, the arduino IDE is okay, but I find it hard using a combination of bluefish & browser for javascript/html, even using developer tools in the browser and console.log to dump stuff debugging is painful. I know I'm drifting off topic, but any suggestions here?
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Locked

Return to “Open Chat”