## Evaluating queue data structures

Working on my book on functional data structures in R, I have implemented three versions of functional queues, two that are not really functional—they need to update a data structure as side effects—and one that is. As far as I can tell, they should have roughly the same performance, but they don’t.

Asymptotically, they all work in $$O(1)$$ time for all operations, this nice figure explains why:

The implementations have two lists and need to move elements from one to the other when you access the front of the queue, so you can imagine all enqueue operations costing twice as many computrones as the other operations and then that can pay for the movement of elements later.

However, the three implementations I have in R have different performances when I measure them. Two of them modify an environment and are not persistent; the third remembers one element more than the others and gives me a persistent data structure. For some reason, the last version has a performance that is about twice as bad as the other two.

I am stumped as to why.

You can reproduce the experiments with the code below—there might be a beer in it for you if you can explain to me why the functional version is so much slower.

## Just sold Meta-programming in R

I just sold Meta-programming in R to Apress. This will then be the third book I publish with them. That is nice—I got the contract yesterday, at the same day as I got confirmation that my copies of Functional Programming in R are in the mail. I will pull down Meta-Programming from Amazon tonight after work, so if you want a copy, you should probably hurry up and get it.