#include #include #include #include #define SYSCLK 14745600UL #ifndef UCSRB # ifdef UCSR1A /* ATmega128 */ # define UCSRA UCSR1A # define UCSRB UCSR1B # define UBRR UBRR1L # define UDR UDR1 # else /* ATmega8 */ # define UCSRA USR # define UCSRB UCR # endif #endif #include /* * Do all the startup-time peripheral initializations. */ void ioinit(void) { UCSRB = _BV(TXEN); /* tx enable */ UBRR = (SYSCLK / (16 * 9600UL)) - 1; /* 9600 Bd */ TCCR1B = _BV(CS12); /* prescaler 256 */ } /* * Send character c down the UART Tx, wait until tx holding register * is empty. */ int uart_putchar(char c) { if (c == '\n') uart_putchar('\r'); loop_until_bit_is_set(UCSRA, UDRE); outb(UDR, c); return 0; } char *bofh[] = { " ### BASTARD OPERATOR FROM HELL ###", "It's backup day today so I'm pissed off. Being the BOFH, however, does have", "it's advantages. I assign the tape device to null - it's so much more", "economical on my time as I don't have to keep getting up to change tapes", "every 5 minutes. And it speeds up backups too, so it can't be all bad.", "A user rings", "\"Do you know why the system is slow?\" they ask", "\"It's probably something to do with...\" I look up today's excuse \".. clock", "speed\"", "\"Oh\" (Not knowing what I'm talking about, they're satisfied) \"Do you know", "when it will be fixed?\"", "\"Fixed? There's 275 users on your machine, and one of them is you. Don't", "be so selfish - logout now and give someone else a chance!\"", "\"But my research results are due in tommorrow and all I need is one page of", "Laser Print..\"", "\"SURE YOU DO. Well; You just keep telling yourself that buddy!\" I hang up.", "Sheesh, you'd really think people would learn not to call!", "The phone rings. It'll be him again, I know. That annoys me. I put on a", "gruff voice", "\"HELLO, SALARIES!\"", "\"Oh, I'm sorry, I've got the wrong number\"", "\"YEAH? Well what's your name buddy? Do you know WASTED phone calls cost", "money? DO YOU? I've got a good mind to subtract your wasted time, my", "wasted time, and the cost of this call from your weekly wages! IN FACT I", "WILL! By the time I've finished with you, YOU'LL OWE US money! WHAT'S", "YOUR NAME - AND DON'T LIE, WE'VE GOT CALLER ID!\"", "I hear the phone drop and the sound of running feet - he's obviously going", "to try and get an alibi by being at the Dean's office. I look up his", "username and find his department. I ring the Dean's secretary.", "\"Hello?\" she answers", "\"Hi, SIMON, B.O.F.H HERE, LISTEN, WHEN THAT GUY COMES RUNNING INTO YOUR", "OFFICE IN ABOUT 10 SECONDS, CAN YOU GIVE HIM A MESSAGE?\"", "\"I think so...\" she says", }; int strlencmp(const char *s1, const char *s2) { return (int)strlen(s1) - (int)strlen(s2); } void main(void) { uint16_t t; size_t i, s = sizeof bofh / sizeof(char *); ioinit(); fdevopen(uart_putchar, NULL, 0); TCNT1 = 0; qsort(bofh, s, sizeof(char *), strcmp); t = TCNT1; printf("time for qsort(strcmp): %g seconds.\n", (double)t * 256 / SYSCLK); TCNT1 = 0; qsort(bofh, s, sizeof(char *), strlencmp); t = TCNT1; printf("time for qsort(strlencmp): %g seconds.\n", (double)t * 256 / SYSCLK); printf("done.\n"); }