My first comment would be why the heck are you using R if you are concerned with processing speed, or are you just prototyping algorithms?
Anyway, Without getting into how I derived it, here is a formula that is much much faster:
Take the log of your signal (-1 if 0):
$$ g[x] = \ln(y[x]) $$
Calculate the following value:
$$ B = \frac{ \begin{array}{c} g[x-6] + g[x-5] + g[x-4] \\ -g[x-3] - g[x-2] - g[x-1] \\ -g[x+1] - g[x+2] - g[x+3] \\ +g[x+4] + g[x+5] + g[x+6] \end{array} }{152} $$
When $ B < 0 $
$$ w[x] = \sqrt{ \frac{-1}{2B} } $$
Otherwise, -1. (Could be due to noise, away from peak )
Here are some results from a test run:
y ln(y) w ------ ------ ----- 114 4.7362 -1.00 167 5.1180 -1.00 233 5.4510 -1.00 326 5.7869 6.69 439 6.0845 6.19 668 6.5043 6.40 769 6.6451 5.32 1003 6.9108 4.83 1213 7.1009 4.97 1435 7.2689 5.01 1613 7.3859 4.92 1645 7.4055 4.81 1645 7.4055 5.13 1722 7.4512 5.58 1550 7.3460 5.00 1464 7.2889 4.91 1301 7.1709 5.42 1072 6.9773 5.10 852 6.7476 4.98 705 6.5582 4.94 526 6.2653 5.25 378 5.9349 6.50 269 5.5947 6.37 156 5.0499 4.42 136 4.9127 2.03
As you can see it is pretty accurate near the peak. There is a rule for generating formulas like this. It can be expanded to cover as wide a stance as desired. (Yeah, I think this will be a future blog article. Thanks for the puzzle.)
I inserted these lines at the end of your code to get my values:
fileConn<-file("y.txt") write(y, fileConn) close(fileConn)
I'll elaborate upon request.