Asked — Edited

Question Regarding The Speed Of The Repeat Funtion In Ez-Script

I find that when using the Repeat function in EZ-Script it takes a long time to loop through anything over a value of say 5000 compared to C++ or python.


Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

United Kingdom

ARC is limited by the speed of your PC. It can carry out literally thousands of commands in a second however communication with the EZ-B will affect performance as will the PC running ARC.

However, what's the question here?


This depends on the number of loops you are running and what they are doing.

Looping to check 8 analog port values will not be great if you don't put in a pause. The reason is it is going over a tcp port to get these values.

Looping to check the value of a digital port can happen very quickly. It is a bit and therefore much less data.

Looping to check a long string from a serial port will be slower and you should probably add a pause to let the serial string complete or check the length of the string to make sure it is complete.

Looping to see if a file exists on a hard drive and then loading that value is dependent on your hard drive speed.

Looping to check if a variable has changed is processor dependent.

It depends on what the loop is doing as to the speed it will run at. I would make your loop and then make adjustments with a sleep step to make sure that the robot is responsive and functions like you want it to.

Also, c++ will be quicker as it is compiled code. Python is very quick also. This is C# which uses a just in time compiler and will be a bit slower than C++ In pretty much everything. This is documented well on the internet. There are advantages to both types of code/compiler. C++ is more optimized for sure.


One more thing...

Scripts are not compiled code and have to run through a script engine. This too takes time, but I have never had an issue where I thought it was a problem.


I think the question is to understand more about programming and how cpu's work. That's a big question, but i'll try to answer it quickly:) Without getting into cpu instructions and how many layers there are between your "app" and the cpu. And, how ez-robot is a new-age approach to productive programming.

Firstly, you can never never never never never compare C++ to Python or EZ-Script or practically anything else. This is because the layer in which C++ operates AND the device you may be referencing is much different. For example, not a lot of people use C++ in Windows anymore so C++ is generally quoted for Microcontrollers (preferred compilers for Arduino/ARM/PIC micros is c++). So writing C++ for a microcontroller will execute as a single isolated process with each instruction taking 100% of clock instructions. You will have to research MIPS to understand how a MIPS compares to a MHZ - because they're not the same and without understanding MIPS or the assembly instruction set, the MHZ value is useless.

So to actually start answering your question, the comparison is off and there's lacking information in the question. For example, if you were to write a simple repeat loop in ez-script, such as...

repeat($x, 0, 5000, 1)

$y = $x * 10


That will execute in 64 milliseconds - which is extremely fast and comparable (if not faster) than Python or C++ with comparable overhead. The code is "compiled" the first time it is ran after editing - which is also what makes it so fast because it runs cached opcode instructions. User-inserted image

That code isn't doing much - so the question you're not asking is most likely about sending or receiving data to/from the ez-b. Now this is a very loaded and complicated question without understand C++ or Python or network programming in general. Forgive me if I leave out details but feel free to ask because it's a big answer.

The EZ-B is dumb. It is a IoT-like device that just sits there waiting for commands. The actual program runs on your device (pc or mobile). The concept was inspired by seeing advanced robots, such as Honda's Asimo and other Darpa robots. This is because unlike all the arduino "robots" and stuff out there, those Asimo-style robots were doing amazing things! And I wanted people to do amazing things. So EZ-Robot is somewhat of a clone of the laboratory grade robotics strategy, with offloading the processing to a more powerful device to produce real robotics. This comes with a slightly different approach to programming.

Unlike an Arduino or microcontroller, you're programing the computer/mobile and not the ez-b. So every time you ask the ez-b to do something, it's being done over a wifi communication using TCP. If you're REPEAT has ez-b commands in it, then you're asking the computer to do a huge pile of work which explains why the experience is different. Once you send data to the ez-b, there's a zillion things happening - specifically the TCP protocol waiting for an acknowledgement that the ez-b has received the command.

This approach makes EZ-Script appear slow - when it is actually doing way more than python or c++ when sending a command to the ezb v4.

Now you're question could have been easier to answer if you asked something like.... "why can't I flash an led 5,000 times a second or write to a neo pixel with Set() commands like I can with Arduino in a Repeat loop?"

Well, that answer is simple and you may need to re-read my entire response again to understand. But ez-robot is not a microcontroller. You can use the ez-robot as a controller to leverage the single-use high-speed instructions of a microcontroller such as arduino, ARM or Microchip PIC.

In short, EZ-Script is very very fast and efficient - however, what you're doing with it matters, such as communicating to an ez-b v4 over a wifi tcp connection :)

The last part I need to touch on since you're asking about how programming works is threading. Notice I'm unable to do much comparison with C++ or python because the question is wrong. That's like asking what is faster, the space shuttle or a bicycle? The question doesn't make sense due to the nature of "what you are doing with it". C++ will always be "faster" but than practically anything, unless you understand how to code in assembly more efficiently than the C++ compiler can compile to opcode. This is where the problem with your question arises because it introduces programming abilities into the equation, and why the question doesn't make sense.

Many people will answer and say well obviously c++ is faster than python, but that answer is lacking real-world scenarios that make the question irrelevant in the first place. Because the space shuttle will be much slower than a bicycle if you were behind it's console:) not knowing how to drive the thing, it most likely wouldn't move... leaving the guy on the bike plenty of time to cross the finish line.

Now back to the ARC way of programming. It's process driven with a multi-threaded approach that is handled for you. This is the most important statement, because multithreaded app development which scales as large as ARC offers in C++ is an absolute nightmare that may put you in the crazy house. ARC handles the multi threading approach for you, without you needing to know anything about it... hence, saving your sanity.

Each control that you see is a separate thread. And each control shares a communication channel to the ez-b, as well as each other. The ControlCommand() is what connects controls together. But each control must run at a managed speed to share resources AND not run faster than another. So all controls are speed limited with a heartbeat that keeps them in sync. This prevents one control from dominating the CPU and leaving your robot unresponsive. So in some cases, EZ-Script or something will appear slow but that's limited by design because it means something else you're doing is causing slowness - such as maybe your computer isn't fast enough for camera tracking.

I never ever ever want to provide a microcontroller programming ability. I never want to be involved in anyone programming a micro directly. This doesn't mean I don't encourage people to - I simply do not wish to participate in teaching people how to flash an LED with arduino because there are already 25 zillion options out there to learn that. Instead, I want people to use one of the 25 zillion options and learn how to leverage Arduino to be used with ez-b. There's never been a fight between ez-robot and Arduino, because they are different things. We're the Engine and Arduino is a Wheel.

Now, don't get me wrong - just because ez-robot doesn't have a fight with Arduino doesn't mean that Arduino doesn't have a fight with ez-robot :). That's a question you would have to ask those users, even though we have absolutely nothing to do with microcontroller programming - nor do we care to. What we care about is providing the high level tools to connect Arduinos, sensors, motors, cameras, etc... together to make robotics actually do something.

I did go a little off topic, but that's a little due to your actual lack of question:) because you're question implied a lack of programming understanding means the answer is much bigger!


Thanks! Sometimes it appears that I know what I'm talking about... Sometimes.


Thanks DJ for the detailed reply, always something new to learn.


I've always wondered why people label the EZ-B the brain, when it is dumb. Not trying to cause waves, but I've always thought of it as the spinal cord. I think it is confuses everything when it is called the brain, because the brain is the pc. Not trying to start anything.



Absolutely right. Spinal cord or Central Nervous System. The biggest confusion newbies have coming here is getting over the fact that this is really a different kind of thing than an Arduino. Both more and less powerful at the same time (can't do anything on its own, but when paired with a computer, can do so much more...).



That is a good point - I've called ARC the soul and ez-b the brain. Guess my reasoning was the ez-b produces the function, while the ARC/pc/mobile is the "thoughts".

Like thoughts of the brain - if that makes sense :)

Not a lot of people know this but EZ-B stood for EZ-Brain not EZ-Board... secret's out!