I l @ ve RuBoard |
To assess COW, I performed measurements of three kinds of functions:
It turns out that the last two both incur a constant (and similar within about 20%) cost per operation, and can roughly be considered together. Assuming for simplicity that mutating-and-extending operations, such as Append() (235ms overhead), and possibly-mutating operations like operator[]() (280ms overhead), will be about equally frequent, the COW_AtomicInt overhead for mutating and possibly-mutating operations is about 260ms per 1,000,000 operations in this implementation. Finally, for each of 2(a) and 2(b), I first used the data shown under Raw Measurements below to hand-calculate a rough prediction of expected relative performance, then ran the test to check actual performance. SUMMARY FOR CASE 2(a): PREDICTION COW_AtomicInt Cost Plain Cost ------------------------------------------------- 1M shallow copies 1M deep copies and dtors 400 and dtors 1600 667K mutations ??? ??? 667K deep copies 1060 extra overhead on 667K deep copies ??? extra overhead on 667K mutations 175 ----- ------ 1635+ 1600+ TEST (program that makes copies in a tight loop, and modifies 33% of them with a single Append and another 33% of them with a single op[]) Running 1000000 iterations with strings of length 50: Plain_FastAlloc 642ms copies: 1000000 allocs: 1000007 Plain 1726ms copies: 1000000 allocs: 1000007 COW_Unsafe 1629ms copies: 1000000 allocs: 666682 COW_AtomicInt 1949ms copies: 1000000 allocs: 666682 COW_AtomicInt2 1925ms copies: 1000000 allocs: 666683 COW_CritSec 10660ms copies: 1000000 allocs: 666682 COW_Mutex 33298ms copies: 1000000 allocs: 666682 SUMMARY FOR CASE 2(b): PREDICTION COW_AtomicInt Cost Plain Cost -------------------------------------------------- 1M shallow copies 1M deep copies and dtors 400 and dtors 1600 1.5M mutations ??? ??? 500K deep copies 800 extra overhead on 500K deep copies ??? extra overhead on 1.5M mutations 390 ----- ------ 1590+ 1600+ TEST (program that makes copies in a tight loop, and modifies 25% of them with three Appends and another 25% of them with three operator[]s) Running 1000000 iterations with strings of length 50: Plain_FastAlloc 683ms copies: 1000000 allocs: 1000007 Plain 1735ms copies: 1000000 allocs: 1000007 COW_Unsafe 1407ms copies: 1000000 allocs: 500007 COW_AtomicInt 1838ms copies: 1000000 allocs: 500007 COW_AtomicInt2 1700ms copies: 1000000 allocs: 500008 COW_CritSec 8507ms copies: 1000000 allocs: 500007 COW_Mutex 31911ms copies: 1000000 allocs: 500007 |
I l @ ve RuBoard |