Actual production time depends on production speed of the thing producing it.
A worker (time=40) is produced by the castle, which has production speed 300.
A barracks (time=100) is produced by the worker, which has build speed 105 and repair speed 40.
The number of "productions" per second is ideally (production speed)/100, although it may deviate from this slightly if the number is not a factor of the frame rate (40/second).
So the expected actual worker production time is about 40/3=~13.3 seconds, and the barracks production time is 100/1.05=~95.2 seconds. Again, expect slight deviations from these numbers since the divisors do not exactly divide the frame rate. Also, buildings start with 5% of their total HP, but the build rate is still approximately (total HP)*(production speed)/(time) HP per second.