3 * Simple program to measure the speed of the various GPIO
6 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
7 ***********************************************************************
8 * This file is part of wiringPi:
9 * https://projects.drogon.net/raspberry-pi/wiringpi/
11 * wiringPi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * wiringPi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************
32 #define FAST_COUNT 10000000
33 #define SLOW_COUNT 1000000
36 void speedTest (int pin, int maxCount)
38 int count, sum, perSec, i ;
39 unsigned int start, end ;
43 for (i = 0 ; i < PASSES ; ++i)
46 for (count = 0 ; count < maxCount ; ++count)
47 digitalWrite (pin, 1) ;
49 printf (" %6d", end - start) ;
51 sum += (end - start) ;
54 digitalWrite (pin, 0) ;
55 printf (". Av: %6dmS", sum / PASSES) ;
56 perSec = (int)(double)maxCount / (double)((double)sum / (double)PASSES) * 1000.0 ;
57 printf (": %7d/sec\n", perSec) ;
63 printf ("Raspberry Pi wiringPi GPIO speed test program\n") ;
64 printf ("=============================================\n") ;
66 // Start the standard way
68 printf ("\nNative wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
71 speedTest (0, FAST_COUNT) ;
75 printf ("\nNative GPIO method: (%8d iterations)\n", FAST_COUNT) ;
76 wiringPiSetupGpio () ;
77 pinMode (17, OUTPUT) ;
78 speedTest (17, FAST_COUNT) ;
82 printf ("\nPhysical pin GPIO method: (%8d iterations)\n", FAST_COUNT) ;
83 wiringPiSetupPhys () ;
84 pinMode (11, OUTPUT) ;
85 speedTest (11, FAST_COUNT) ;
87 // Switch to SYS mode:
89 system ("/usr/local/bin/gpio export 17 out") ;
90 printf ("\n/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
92 speedTest (17, SLOW_COUNT) ;