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
39 uint32_t start, end, count, sum, perSec ;
41 printf ("Raspberry Pi wiringPi speed test program\n") ;
43 // Start the standard way
45 if (wiringPiSetup () == -1)
48 printf ("Native wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
53 for (i = 0 ; i < 3 ; ++i)
55 printf (" Pass: %d: ", i) ;
59 for (count = 0 ; count < FAST_COUNT ; ++count)
62 printf (" %8dmS\n", end - start) ;
63 sum += (end - start) ;
66 printf (" Average: %8dmS", sum / 3) ;
67 perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
68 printf (": %6d/sec\n", perSec) ;
71 printf ("Native GPIO method: (%8d iterations)\n", FAST_COUNT) ;
73 if (wiringPiSetupGpio () == -1)
76 pinMode (17, OUTPUT) ;
79 for (i = 0 ; i < 3 ; ++i)
81 printf (" Pass: %d: ", i) ;
85 for (count = 0 ; count < 10000000 ; ++count)
86 digitalWrite (17, 1) ;
88 printf (" %8dmS\n", end - start) ;
89 sum += (end - start) ;
91 digitalWrite (17, 0) ;
92 printf (" Average: %8dmS", sum / 3) ;
93 perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
94 printf (": %6d/sec\n", perSec) ;
97 // Switch to SYS mode:
99 if (wiringPiSetupSys () == -1)
102 printf ("/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
105 for (i = 0 ; i < 3 ; ++i)
107 printf (" Pass: %d: ", i) ;
111 for (count = 0 ; count < SLOW_COUNT ; ++count)
112 digitalWrite (17, 1) ;
114 printf (" %8dmS\n", end - start) ;
115 sum += (end - start) ;
117 digitalWrite (17, 0) ;
118 printf (" Average: %8dmS", sum / 3) ;
119 perSec = (int)(double)SLOW_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
120 printf (": %6d/sec\n", perSec) ;