3 ms·
/* ** Test procedure for ParseRfc822Date */ void TestParseRfc822Date(void){ time_t t1, t2; for(t1=0; t1<0x7fffffff; t1 += 127){
by pjc50 5y ago
/*
** Test procedure for ParseRfc822Date
*/
void TestParseRfc822Date(void){
time_t t1, t2;
for(t1=0; t1<0x7fffffff; t1 += 127){
t2 = ParseRfc822Date(Rfc822Date(t1));
assert( t1==t2 );
}
}
There's only two billion integers, guess we can test them all. Well, substantially fewer than two billion with that skip. I wonder if that completes in a few seconds.
- ithkuil 5y agoComputers are insanely fast
- tyingq 5y agoAnother comment shows 10 seconds on a relatively decent CPU from 2017. So it is a fairly heavyweight task, though I suppose could be rewritten to use more than one core.
- ithkuil 5y agoyeah, that's a lot of iterations :-) I was curious to see how my M1 compares to my intel 2019 macbook pro: M1: /tmp/tt 8.42s user 0.01s system 99% cpu 8.435 total 2,6 GHz 6-Core Intel Core i7 /tmp/tt 15.69s user 0.03s system 98% cpu 15.888 total /tmp/tt 15.69s user 0.03s system 98% cpu 15.888 total
- nneonneo 5y agoThis loop doesn’t test them all - it tests every 1/127th integer, so it only runs about 16 million times.
- Cthulhu_ 5y agoAnd a modern CPU runs billions of instructions per second, so it shouldn't take too long at all. Depends on the implementation of the function as well though, and how the compiler can optimize, unroll or optimize both the function under test and the test itself.
- deleted 5y ago[deleted]
- unwind 5y agoThat was quite easy to cut and paste and compile: $ time ./althttpd-time-parse Test completed in 10518961 us real 0m10,521s user 0m10,486s sys 0m0,004s The "Test completed" line is from my main() "driver", I wanted to measure time inline too and the measurements seem to agree. This is on a Dell Latitude featuring a Core i5-7300U at 2.6 GHz, running Ubuntu 20.10.
- taspeotis 5y agohttps://randomascii.wordpress.com/2014/01/27/theres-only-four-billion-floatsso-test-them-all/ https://randomascii.wordpress.com/2014/01/27/theres-only-fou...
- postalrat 5y agoHow would you write a better test? IMO most tests are fundamentally flawed. The way most testing is done it would be easier and better to just write everything twice, have a method to compare results, and hope you got it right at least once.
- louisvgchi 5y agoI do think of tests as a kind of double accounting.
- asveikau 5y agoLooks like test code, rather than something that runs when serving in production. It fails an assert if the parse doesn't work I guess?