It sounds a lot better to use the second example with the past perfect because we are referring to a past time before another past time. That is exactly where we would use the past perfect. By the time it was 5, I had given him the book.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.