CodeWalrus

Development => Hardware => Topic started by: semiprocoder on September 29, 2015, 10:08:03 PM

Title: Arduino Benchmark
Post by: semiprocoder on September 29, 2015, 10:08:03 PM
About half a year ago I made a benchmark for the arduino because I wanted to see how much faster my then new arduino due was than my arduino uno and micro. I don't know why, but I decided that I will(perhaps, not sure yet) start programming arduino again(since that benchmark I pretty much didn't even touch arduino anymore). The main reason that I stopped arduino was cause I suck at hardware stuff so I couldn't really do anything special, but I did make pong(and I tried to make don't touch the spikes(an amazing remake of flappy bird), but resistive touchscreens are not really meant for capacitive uses), if anyone is interested.

Anyways, back to the arduinos and my benchmark. My benchmark has a large macro, which is divided by the time the arduino took to complete the benchmark. That time is the score the arduino gets at the end. The due turned out to indeed be a lot faster and got a score almost six times as big as the uno and micro, and, unsurprisingly, and my micro got a slightly lower(but practically insignificant) score compared to my uno. Here is my code:


#define ITER 200000L
#define SCORE_DIVIDER 99999999L
#define UNO_SCORE 563L// I might eventually use this to guess which arduino you are benchmarking
#define MICRO_SCORE 559L
#define DUE_SCORE 3301L
#define MALLOC_SIZE 256
void printFloat(float value, unsigned long precision){
   Serial.print(int(value));
   Serial.print(".");
   unsigned long frac;
   if (value >= 0)
      frac = (value - long(value)) * precision;
   else
      frac = (long(value) - value) * precision;
   Serial.println(frac, DEC);
}
void setup() {
   Serial.begin(57600);
   long Millis=millis();
   long increment = 0;
   float f = 0.0f;
   Serial.println("checking float performance using random");
   for (; increment < ITER; increment++) {
      f = random(0.0f, (float)increment);
   }
   Serial.print("rand performance time taken: ");
   Serial.println(millis() - Millis);
   Millis = millis();
   Serial.println("now calculating PI using Newtonian method...");
   long Millis2 = millis();
   float pi = 0.0f;
   float multiplier = 1.0f;
   for (float incrementf = 0.0f, increment=0; increment < ITER; incrementf+=1.0f, increment++){
      pi += 4.0f / (incrementf*2.0f + 1.0f)*multiplier;
      multiplier *= -1.0f;
   }
   Serial.print("PI estimating time: ");
   Serial.print(millis() - Millis2);
   Millis2 = millis();
   Serial.print(" PI estimate: ");
   Serial.println(pi, 8);
   Serial.println("About to test polar to rectangular coordinate conversion: ");
   long Millis3 = millis();
   float X = 0.0f;
   float Y = 0.0f;
   f = 0.0f;
   for (long i = 0L; i < ITER/3; i++, f+=PI/1000.0f){
      X = cos(f)*((float)i)/1000.0f;
      Y = sin(f)*((float)i) / 1000.0f;
   }
   Serial.print("Polar to rect coords converting time: ");
   Serial.println(millis() - Millis3);
   Serial.print("X: ");
   Serial.println(X, 8);
   Serial.print("Y: ");
   Serial.println(Y, 8);
   Millis3 = millis();
   Serial.println("now testing mem write speed(mallocing and freeing pointers):");
   long Millis4;
   for (long i = 0; i < ITER/4; i++){
      char *j = (char*)malloc(MALLOC_SIZE);
      char *f = j;
      for (int i = 0; i < MALLOC_SIZE; i++){
         *f = 'n';//just some random value to initialize the whole array of chars with
         f++;
      }
      free(j);
   }
   Serial.print("Ram test finished in: ");
   Serial.print(millis() - Millis4);
   Serial.println(" milliseconds");
   Serial.print("malloc size is: ");
   Serial.println(MALLOC_SIZE);
   Millis4 = millis();
   long score = Millis + Millis2 + Millis3+Millis4;
   score = SCORE_DIVIDER / score;
   Serial.println("Your arduino's score is: ");
   Serial.print(score);
}

void loop() {
}


-----------------------------------------

By the way, should I make myself a thread just for my old code(or just make this thread for all my code), cause I have a bunch of old codes I want to showcase(like pong for android, 2d minecraft in processing, 2048 in processing, a 2d platformer I made that I need to restore(well finish and fix not restore I don't have any way of doing that) because I made it on my school computer, so my comp doesn't have the working version and the version on my comp is outdated). Not all of it is polished or that good or anything, but some of my code(in my opinion) is not too bad.

Edit (Streetwalrus): merged double post.
Title: Re: Arduino Benchmark
Post by: novenary on October 01, 2015, 12:14:11 PM
You should keep it all in one thread unless you have a big project to showcase, in which case it's better to create a new thread for it. :)
Title: Re: Arduino Benchmark
Post by: semiprocoder on October 01, 2015, 07:30:14 PM
Yeah thats what I was planning to do.
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 01, 2015, 07:38:41 PM
Nice idea of performance testing.

It might be a little off-topic, but I wanted to say this about arduino for aa long time now.
I don't like some concepts of it and their results.
Like arduino is great for real EE beginners or for quick prototyping, but in no way is the arduino code style efficient; its just slow with all that abstraction and it doesn't make awitching to real ARM-C or AVR-C easy at all. Even the few extra MHz of the due or the different architecture will change that.
Another thing that I don't like is that everything has to be arduino compatible.
And the final thing is, that the concept if using shields is a bad thing in my opinion. You just end up with a huge, expensive stack of PCBs and nothing permanent.
Apart from that, it has a great and capable community.

These are also reasons (especially the bad coding style and the C++) that we don't make the microcat arduino compatible.
Title: Re: Arduino Benchmark
Post by: p4nix on October 01, 2015, 07:44:03 PM
Yeah, there are guys using the whole circuit board although they could come up with something more stable and smaller even on breadboard if they just use what they need (the micro + power supply + their stuff)...
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 01, 2015, 07:52:42 PM
Quote from: p4nix on October 01, 2015, 07:44:03 PM
Yeah, there are guys using the whole circuit board although they could come up with something more stable and smaller even on breadboard if they just use what they need (the micro + power supply + their stuff)...
That is what I was doing in the past (soldering it standalone). But I am switching to real register based c now.
Title: Re: Arduino Benchmark
Post by: semiprocoder on October 01, 2015, 08:01:34 PM
I don't know. Arduino seems pretty fast too me. Of course it's no asm(which I don't know yet but would be happy if someone sent me a nice tutorial, although I'm not really trying to do so right now), but still. Compared to something like ti basic, it whizzes along at ridiculous speed. The main reason I personally don't really like arduino(although I still like it cause of some of the uses for it) is cause I suck at hardware stuff(I can still do some simple wire connecting on a breadboard obviously, but not too much more), don't really feel like soldering, and I really don't like that tiny 2kb of ram. Cmon, it should have more. Also I tried using the due for some of this stuff but still, it is not compatible with like any arduino shields, which is annoying.

Also I don't know, shields are kind of nice. As I said before not good at hardware so I really like shields because they make it easier to do everything.
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 02, 2015, 06:53:10 AM
Quote from: semiprocoder on October 01, 2015, 08:01:34 PM
I don't know. Arduino seems pretty fast too me. Of course it's no asm(which I don't know yet but would be happy if someone sent me a nice tutorial, although I'm not really trying to do so right now), but still. Compared to something like ti basic, it whizzes along at ridiculous speed. The main reason I personally don't really like arduino(although I still like it cause of some of the uses for it) is cause I suck at hardware stuff(I can still do some simple wire connecting on a breadboard obviously, but not too much more), don't really feel like soldering, and I really don't like that tiny 2kb of ram. Cmon, it should have more. Also I tried using the due for some of this stuff but still, it is not compatible with like any arduino shields, which is annoying.

Also I don't know, shields are kind of nice. As I said before not good at hardware so I really like shields because they make it easier to do everything.
Yes I see the speed difference. If you use arduino, try using the proper C functions and registers, like PORTA and so instead of digitalWrite and digitalRead.
These are big problems of the arduino platform as digitalRead and write are so abstracted that they are very slow. ASM is not required in the most cases except inline assembly for speed critical parts.
C++ is not the particulary best choice for a such limited platform (C would be more appropriate).

Back to the microcat. I used a new processor that is currently not usable in open source projects as it has no API yet.
We work on this so others can use our processor in their projects too.
Our microprocessor is only 2-3 EUR more expensive than the arduino unos processor, but has USB 2.0, multiple serial ports, infrared, parallel io controller, high speed multimedia card interface (SD support), 128KB ram with the possibility of executing machine code from there, 512KB flash, Serial and USB boot loader right from factory in internal ROM, ~50 io pins, up to 120MHz clock, ARMv7 processor architecture, built-in real time clock, SPI up to 40MHz, I2C, I2S, 16 bit PWM, 10 bit DAC.

Making a small PCB breakout of it and using the API that we are building currently, it should be an awesome platform.
Title: Re: Arduino Benchmark
Post by: semiprocoder on October 02, 2015, 07:19:07 PM
Well, I agree that digitalwrite and read are really slow, cause bit manipulation is pretty fast compared to bit maniuplation and bunch of like error checking or whatever it was(I looked at the source a while ago but don't remember what it is so I'm guessing here). But the problem with just using PORTB, PORTC, PORTD is that it doesn't work on all the arduinos and changes from like uno to due. Of course, when I actually need speed I would use the bit manipulation, but otherwise, eh.

Also a question about the microcat: Are any ports going to be open for use, with the screen and all being built in, and what voltage and amperage are they running at? Also the API is going to be in c, right?

And I don't extensively use c++. I learned c and then self taught some c++, but I don't really use it(don't even remember how to use cout), unless I want to make a library with classes or something. Also I use int *i=new int
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 02, 2015, 08:41:44 PM
Also a question about the microcat: Are any ports going to be open for use, with the screen and all being built in, and what voltage and amperage are they running at? Also the API is going to be in c, right?

And I don't extensively use c++. I learned c and then self taught some c++, but I don't really use it(don't even remember how to use cout), unless I want to make a library with classes or something. Also I use int *i=new int(x)(for some reason brackets are being a bullet point) when I want to make variable length arrays and feel lazy, cause I don't always feel like using malloc and then keep track of my pointers and stuff.
[/quote]
Of course will there. There will be 3 SPI, 1 (infrared) serial, 1 I2C port and > 15 free GPIO pins that will be usable for anything that the game or OS developer wants.
One SPI port is occupied with the OLED, one serial port is occupied with the ESP8266, one serial port is for testing, and the usb port is hooked up to the USB jack (USB host and slave).
The operating voltage of the IO is 3.3v, the internal voltage is 1.2v. The processor will draw up to 100mA maximum (if i did not missread).
And the API will be C, right.

The brackets are interpreted as so called "Bulletin Board Code" or BBCode which is a markup language for forums.
Try putting it into [code]myval[x][\code] boxes (with this slash: /).
Title: Re: Arduino Benchmark
Post by: semiprocoder on October 03, 2015, 07:49:43 PM
Thats nice. So you will be able to use it like an arduino and as a retro game player-. Also maybe some old fashioned serial communication for games just for the heck of it. Also will you just connect a keyboard to the microcat or will it have its own dedicated set of buttons. Will it have a joystick?

Also, straying from hardware a little bit, what do you plan the os to be like. Will it be like the ti 84 with a simple file interface and a main screen, or will it be like a skinned down version of linux?
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 05, 2015, 12:21:32 AM
Quote from: semiprocoder on October 03, 2015, 07:49:43 PM
Thats nice. So you will be able to use it like an arduino and as a retro game player-. Also maybe some old fashioned serial communication for games just for the heck of it. Also will you just connect a keyboard to the microcat or will it have its own dedicated set of buttons. Will it have a joystick?

Also, straying from hardware a little bit, what do you plan the os to be like. Will it be like the ti 84 with a simple file interface and a main screen, or will it be like a skinned down version of linux?
Well it has USB and serial communication and WiFi (last one allows for multiplayer across the world :))
It had a joystick, but we replaced it for a few reasons with a  dpad. It has 4 direction keys on the left and 4 action buttons on the right. It also has a game independent home and power button.

About the os I thought to make it something in between something like scaled down Linux and a 84+ style OS structure.
Title: Re: Arduino Benchmark
Post by: Dream of Omnimaga on October 05, 2015, 04:18:27 AM
The OS should probably be simple at first but provide some functionalities that phone users would commonly use.  Just as long as launching games is as easy as it can get, unlike some consoles.
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 05, 2015, 02:12:09 PM
Quote from: DJ Omnimaga on October 05, 2015, 04:18:27 AM
The OS should probably be simple at first but provide some functionalities that phone users would commonly use.  Just as long as launching games is as easy as it can get, unlike some consoles.
Well we plan having a nice colorful loader and settings app which will probably be in flash, but they could end up being put onto the SD card.
And yes the os won't get too big.
Title: Re: Arduino Benchmark
Post by: semiprocoder on October 05, 2015, 11:36:37 PM
That's awesome. I don't really like having to go through an entire complex os just to get to games or to access the ports. Also I don't really know linux commands because I am too lazy to learn them, but a simple os makes everything easier. Also do you plan to make the api like arduino. I know it is in c but I mean like will the functions be similar? Or will you have an api completely different and evolving from arduino.
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 05, 2015, 11:43:24 PM


Quote from: semiprocoder on October 05, 2015, 11:36:37 PM
That's awesome. I don't really like having to go through an entire complex os just to get to games or to access the ports. Also I don't really know linux commands because I am too lazy to learn them, but a simple os makes everything easier. Also do you plan to make the api like arduino. I know it is in c but I mean like will the functions be similar? Or will you have an api completely different and evolving from arduino.

Well you won't expect a digitalwrite command, but I will probably provide some arduino like features, though most things will be abstracted away. Because the code should compile on the PC as well :)
You should be able to test and debug right in your PC and compile all games for Windows, Linux and Mac.
Also I plan having a privileged mode and a standard mode. Privileged mode games can control the hardware, change clock speed, set the real-time clock and other settings and leave their folder on the SD card.
Title: Re: Arduino Benchmark
Post by: Dream of Omnimaga on October 06, 2015, 12:17:32 AM
Quote from: DarkestEx on October 05, 2015, 02:12:09 PM
Quote from: DJ Omnimaga on October 05, 2015, 04:18:27 AM
The OS should probably be simple at first but provide some functionalities that phone users would commonly use.  Just as long as launching games is as easy as it can get, unlike some consoles.
Well we plan having a nice colorful loader and settings app which will probably be in flash, but they could end up being put onto the SD card.
And yes the os won't get too big.
Cool. My issue is stuff like the TI-Nspire, which is supposed to be a calculator, yet the calculator is called a scratchpad and it takes a bit to figure out how to add, substract and stuff. And something to run games should present you the game list as the main focus IMHO. Oh and yeah it's better to start with a small OS then expand, since not only you have to spend hundreds of hours on the hardware, but another hundred or more learning how to write an OS from scratch.
Title: Re: Arduino Benchmark
Post by: semiprocoder on October 06, 2015, 02:56:04 AM
That's awesome.
Quote from: DarkestEx on October 05, 2015, 11:43:24 PM
Well you won't expect a digitalwrite command, but I will probably provide some arduino like features, though most things will be abstracted away. Because the code should compile on the PC as well :)
You should be able to test and debug right in your PC and compile all games for Windows, Linux and Mac.
Also I plan having a privileged mode and a standard mode. Privileged mode games can control the hardware, change clock speed, set the real-time clock and other settings and leave their folder on the SD card.

Thats awesome. Do you plan to have the emulator to run at the clock speed of the microcat. And how will privileged mode work on the debugger. Also do you plan to make the debugger free, or will it only be available to those who buy the microcat? And will the ports be simulated on the emulator, or would they just not be used? :P
Title: Re: Arduino Benchmark
Post by: Dream of Omnimaga on October 06, 2015, 07:01:01 PM
Wait, do you mean an Microcat emulator for computers or do you mean Microcat OS with emulation features?
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 06, 2015, 07:14:19 PM
Quote from: semiprocoder on October 06, 2015, 02:56:04 AM
That's awesome.
Quote from: DarkestEx on October 05, 2015, 11:43:24 PM
Well you won't expect a digitalwrite command, but I will probably provide some arduino like features, though most things will be abstracted away. Because the code should compile on the PC as well :)
You should be able to test and debug right in your PC and compile all games for Windows, Linux and Mac.
Also I plan having a privileged mode and a standard mode. Privileged mode games can control the hardware, change clock speed, set the real-time clock and other settings and leave their folder on the SD card.

Thats awesome. Do you plan to have the emulator to run at the clock speed of the microcat. And how will privileged mode work on the debugger. Also do you plan to make the debugger free, or will it only be available to those who buy the microcat? And will the ports be simulated on the emulator, or would they just not be used? :P
Quote from: DJ Omnimaga on October 06, 2015, 07:01:01 PM
Wait, do you mean an Microcat emulator for computers or do you mean Microcat OS with emulation features?
Well actually I am not going to make an emulator, but as the microcat API is written in C, I plan making a ARM and a PC backend for the API calls. So all the microcat functions will be ported to PC.
So microcat applications will compile for Windows, Linux and Mac and for the ARM core of the console.
It has many benefits, that an emulator wouldn't have such as being able to use readily available tools to debug and write software and to show games to people who don't have a microcat and let them develop software for it as if they would own one.
The applications will run at microcat speed so that people don't have to worry about timing problems. About the ports, I don't know yet. Maybe they can be used or maybe they can't. I could use pipes to deal with them and redirect the port actions to another program that can deal with them. The API should be available to anybody who wants to develop for the platform. We hope that people buy it, but we don't force them to. About privileged mode, I assume it works like unprivileged mode on the PC.
Title: Re: Arduino Benchmark
Post by: Dream of Omnimaga on October 07, 2015, 02:44:41 AM
Ah thanks for the clarification. That is good news since it will make it easier to test stuff quickly. When I make 84+CSE games I can immediately test in WabbitEmu without having to transfer files and stuff.


Also do you mean that the API will also cost money? IMHO it should be made much cheaper than the console and free for console owners, else with so many people under 18 years old or at school, a paid API or SDK would considerably harm your chances of getting softwares, plus people would probably immediately make third-party freeware alternatives or legal ways to allow free use of the software anyway (as it happened with PICO-8). That's something to consider with the demographics around here.

Or perhaps there could be premium features such as a watermark that can be removed when paying (or paying higher) for the API

I'm definitively buying the console when (I hope it's not if :P) it comes out, though. :)
Title: Re: Arduino Benchmark
Post by: DarkestEx on October 07, 2015, 05:07:07 AM
Quote from: DJ Omnimaga on October 07, 2015, 02:44:41 AM
Ah thanks for the clarification. That is good news since it will make it easier to test stuff quickly. When I make 84+CSE games I can immediately test in WabbitEmu without having to transfer files and stuff.


Also do you mean that the API will also cost money? IMHO it should be made much cheaper than the console and free for console owners, else with so many people under 18 years old or at school, a paid API or SDK would considerably harm your chances of getting softwares, plus people would probably immediately make third-party freeware alternatives or legal ways to allow free use of the software anyway (as it happened with PICO-8). That's something to consider with the demographics around here.

Or perhaps there could be premium features such as a watermark that can be removed when paying (or paying higher) for the API

I'm definitively buying the console when (I hope it's not if [emoji14]) it comes out, though. :)
I was never taking about making it non-free. I actually stated the opposite in my last post [emoji14]
The API is going to be open source.
Apart from that, I am not 18 either but managed it to spend over 250 euro on proto parts (adekto another 250).
Title: Re: Arduino Benchmark
Post by: p4nix on October 07, 2015, 04:10:00 PM
I think closing down something indie wouldn't work anyway, so paid/restricted API and stuff would be only senseful in a profitable way if you hit a few 10k users...
Title: Re: Arduino Benchmark
Post by: Dream of Omnimaga on October 08, 2015, 06:06:18 AM
I guess I misunderstood your post Darkest, specifically the part below:

QuoteThe API should be available to anybody who wants to develop for the platform. We hope that people buy it, but we don't force them to

I thought that "it" refered to the API :P I'M glad that it's free and open-source :) (just make sure it has a license, especilaly if you release it early)


And yeah the 18+ thing is that in USA most people under 18 have zero income or their parents have full control on what they spend their money on. >.<