When using MathLink installable programs based on
WiringPi, it is possible to really crank up the cycles. Here's the c code:
#include <wiringPi.h>
#include "mathlink.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int pinread(int pin);
int pinhi(int pin);
int pinlo(int pin);
int pincycle(int pin, int num);
void multiread(int pin, int num);
int main(int argc, char *argv[]){
wiringPiSetupGpio();
return MLMain(argc, argv);
}
int pinread(int pin) {
pinMode(pin, INPUT);
return digitalRead(pin);
}
int pinhi(int pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin,1);
return 0;
}
int pinlo(int pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin,0);
return 0;
}
int pincycle(int pin, int num) {
int i;
for (i=0;i<num;i++) {
pinhi(pin);
pinlo(pin);
}
return 0;
}
void multiread(int pin, int num) {
int i;
int val[num];
pinMode(pin, INPUT);
for (i=0;i<num;i++) {
val[i]=digitalRead(pin);
}
MLPutInteger32List(stdlink, val, num);
return ;
}
And I get results fairly close to what
has been reported in other speed tests:
10^6/(pinCycle[24,10^6]//AbsoluteTiming//First)
(* 1.41x10^6 *)
out = multiRead[23,10^6]//AbsoluteTiming;
10^6/out[[1]]
(* 3.29x10^6 *)