User avatar
joan
Posts: 13459
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Simple GPIO performance benchmark

Sun Oct 30, 2016 9:35 am

@mc007ibi

Could you post the code you used to get your figures so we can repeat your tests?


fivdi
Posts: 203
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Simple GPIO performance benchmark

Sun Oct 30, 2016 9:54 am

The test software looks fine :)

What does the test output to the screen? Something similar to "100000 write ops per second" which would imply a frequency of 50KHz or something similar to "2000000 write ops per second" which would imply a frequency of 1MHz?

If the scope can't handle above 1MHz I'd expect issues as the pigpio JavaScript test program can output at above 1MHz.

User avatar
mc007ibi
Posts: 66
Joined: Wed Dec 16, 2015 7:36 pm
Location: barcelona

Re: Simple GPIO performance benchmark

Sun Oct 30, 2016 10:00 am

@ fivdi: yeah, sorry, the video was incomplete. However, your benchmark script outputs here the same as in your repos's readme : 2.393.533 write ops per second and around 50Kc on the oscilloscope.

I am not sure how much GPIO performance is really needed by PI users but i guess people do their time critical code in C just anyways. Being limited to kHz ranges, I guess there isn't really much you can do then with a script language, except some basic stuff. I just made some basic performance tests with Jerry-Script and its blazing fast. I gonna wire the pigpio native code in there let you know how it went.
g

fivdi
Posts: 203
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Simple GPIO performance benchmark

Sun Oct 30, 2016 3:45 pm

Hmm, if the output of the test program is 2.393.533, the frequency measured on the scope should be about 1.2MHz. However, as mentioned above, the scope can't handle frequencies above 1MHz.

Below is a variant of the test program that sets the level of the GPIO to 1 and 0 twice in succession to waste time and lower the frequency to below 1MHz for the scope. If the assumptions I'm making are correct, the scope should measure a frequency of about 600KHz.

Code: Select all

use strict';

var Gpio = require('../').Gpio,
  led = new Gpio(17, {mode: Gpio.OUTPUT}),
  time,
  ops,
  i;

time = process.hrtime();

for (i = 0; i !== 2000000; i += 1) {
  led.digitalWrite(1);
  led.digitalWrite(1);
  led.digitalWrite(0);
  led.digitalWrite(0);
}

time = process.hrtime(time);
ops = Math.floor((i * 4) / (time[0] + time[1] / 1E9));

console.log('  ' + ops + ' write ops per second');

User avatar
mc007ibi
Posts: 66
Joined: Wed Dec 16, 2015 7:36 pm
Location: barcelona

Re: Simple GPIO performance benchmark

Sun Oct 30, 2016 8:50 pm

@ fivdi ok, will try that too :D I am eager to figure out why JS is slower by 50% whilst still calling 2 native functions "only". Is that because of node-gyp being slow, or the V8 Js engine? I remember Python's source code written somehow way more lightweight in many aspects than the actually heavy v8, despite its doing quite some outsourcing to ASM. Anyways, I gonna pop up in your repo sometime soon. Possibly there are ways to get your JS binding faster than this...

fivdi
Posts: 203
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Simple GPIO performance benchmark

Sun Oct 30, 2016 9:50 pm

JavaScript isn't 50% slower. In this case it's an order of magnitude faster.

User avatar
mc007ibi
Posts: 66
Joined: Wed Dec 16, 2015 7:36 pm
Location: barcelona

Re: Simple GPIO performance benchmark

Mon Oct 31, 2016 12:02 pm

@fivdi Whoa, how is that ? I thought more cycles are more speed? Anyhow, don't bother. There is btw. built-in support for GPIO in JerryScript but rather experimental. First tests showed slow results and it did run out of memory. They also have a weird native implementation, requiring async functions for most GPIO functions.

jonathanscottjames
Posts: 6
Joined: Wed Jul 27, 2016 12:04 pm

Re: Simple GPIO performance benchmark

Sun Mar 04, 2018 1:54 pm

this is a pi 3
it's obvious that the peak misalignment average timing is almost a full 16 bit interval after 160 bits which indicates it has moments of stabillitry
https://www.facebook.com/1960622427301192

looking at 10us / cm(.1ms full screen) the time for an average 16 flip flop data output is stable about 55 us to complete 16 bit values and a 17th sync pulse
https://www.facebook.com/1960603000636468

(scope is set to .5us..) 3.25 microseconds minimum for a 1 bit flip flop
https://www.facebook.com/1960594600637308

(scope setting .5us)
https://www.facebook.com/1960594557303979

(scope setting 10us)
https://www.facebook.com/1960594287304006

github of this generic python script test program:
https://github.com/jonathanscottjames/j ... rst_ave.py

Code: Select all

#!/usr/bin/env python27
import RPi.GPIO as GPIO
from datetime import datetime
import time

GPIO.setmode(GPIO.BCM)  # set board mode to Broadcom
countingb=0
countington=0
timington=time.time()
averagington=0
average=0
maxington=0
minington=0

GPIO.setwarnings(False)  #this supresses error messages to avoid clutter
GPIO.setup(2, GPIO.IN, pull_up_down=GPIO.PUD_UP) #set pull up resistor so grounding will change it
GPIO.setup(3, GPIO.OUT)  #set gpio 4 to output mode
GPIO.setup(4, GPIO.OUT)  #set gpio 4 to output mode
#GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

#************** end setup *****************************
#   `

timington = time.time()+1
while True:
    GPIO.output(4, 1)
    GPIO.output(4, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    GPIO.output(3, 1)
    GPIO.output(3, 0)
    countington=countington+1
    if ((timington)<time.time()):
        print(countington, end=" ")
        countingb=countingb+1
        average=average+countington
        if average>2000000000:
            average=countington
            countingb=1
        averagington=average/countingb
        if(countington>maxington):
            maxington=countington
            print(" ")
            print ("max=",maxington," min=",minington," avr=",averagington)
        if(minington==0):
            minington=countington
        if(countington<minington):
            minington=countington
            print(" ")
            print ("max=",maxington," min=",minington," avr=",averagington)
        countington=0
        timington=time.time()+1
           
jonathanscottjames for president

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 11 guests