Function to measure tree lenght