Dear Joe,

There is an error in your submission, it should be PrimeQ [ n ] , and for large number of primes, replaceall will give an error becuase MaxIterations is by default 2^16. So I changed the code of the 3 solutions now to measure the time needed to generate the primes and to measure computational duration for generating 100000 primes:

AbsoluteTiming[ReplaceRepeated[{{},3,0},{r_,n_,c_/;c<num}:>If[PrimeQ[n]&&PrimeQ[n+2],{Append[r,{n,n+2}],n+4,c+1},{r,n+2,c}],MaxIterations->\[Infinity]]//First;]

m=num;

n=1;

f=0;

AbsoluteTiming[res=Reap[While[f<m,If[PrimeQ[Prime[n]+2],Sow[Prime[n]];f++];n++;];][[2,1]];]

twins={res,res+2}\[Transpose];

AbsoluteTiming[Rest[NestList[(NestWhile[#+1&,#,!PrimeQ[#1]||!PrimeQ[#3]&,3]-1)&,1,num]-1];]

times:

{74.419518, Null}{5.666652, Null}{50.630102, Null}

So although the code with replaceall is very neat, it is slow compared to the others. The main problem with Joe's solution is that primes get more and more separated for large numbers, so the stepping with 2 or 4 makes it slow.