CvPlayer::getCivicAnarchyLength
Short summary: if you are immune to anarchy, 0 turns. If not, 1 to 100

inclusive turns.
+1 turn base cost
+1 turn per civic changed
+ additional turns based on the number of cities you have ( a function of map size - on standard, the factor is 12.5, so you get an extra turn with 13 cities, two extra turns with 25, and so on)
multiplied by the game speed modifier ( 67% / 100% / 150% / 200%); yes, anarchy at marathon speed is only doubled.
multiplied be the era modifier of your starting era
50% ancient and classical
40% medieval and renaissance
34% industrial and beyond.
All of these constants are tucked away into XML files - ie, trivial to mod.
Today's useless micromanagement tip - change civics before you found/acquire new cities.