Counting Primes in Arithmetic Progressions

(* pi(x) counts the primes at most x, pi1mod4 counts the primes congruent to 1 mod 4, pi3mod4 counts those congruent to 3 mod 4. Note pi3mod4 = pi-pi1mod4-1 (remember 2 is a prime!) *)
pi[x_] :=PrimePi[x]
pi1mod4[x_] := Sum[If[Mod[Prime[n],4] == 1 ,1,0],{n,1,pi[x]}] - If[Prime[pi[x]] > x && Mod[Prime[x] ,4] == 1,1,0];
pi3mod4[x_] := Sum[If[Mod[Prime[n],4] == 3 ,1,0],{n,1,pi[x]}] - If[Prime[pi[x]] > x && Mod[Prime[x] ,4] ==3,1,0];
fastpi3mod4[x_] := pi(x) - pi1mod3[x] - If[x ≥ 2, 1,0];

Manipulate[Plot[{pi3mod4[x],pi1mod4[x],(pi[x]-1)/2},{x,center,center+range}], {center,3,40000}, {range,10,10000}]

Manipulate[Plot[pi3mod4[x]-pi1mod4[x],{x,center,center+range}], {center,3,40000}, {range,10,10000}]

Print["For more information, see ", Hyperlink["http://mathworld.wolfram.com/ChebyshevBias.html"], " as well as the paper by ",Hyperlink["Rubinstein and Sarnak on Chebyshev's Bias","http://projecteuclid.org/DPubS/Repository/1.0/Disseminate?view=body&id=pdf_1&handle=euclid.em/1048515870"],"."]

Prime[2946] (* where 1 mod 4 beats 3 mod 4 for the first time *)

Prime[23338590792] (* where 1 mod 4 first beats 3 mod 4 ?? *)

countprimes[num_] := Module[{},
primelist = {};
primelist1mod4 = {};
primelist3mod4 = {};
numprimes = 0;
numprimes1mod4 = 0;
numprimes3mod4 = 0;
primediff = {};
For[i = 1, i ≤ num, i++,
{
p = Prime[i];
numprimes = numprimes + 1;
primelist = AppendTo[primelist, {p,numprimes}];
If[Mod[p,4] == 1, 
{
numprimes1mod4 = numprimes1mod4 + 1;
primelist1mod4 = AppendTo[primelist1mod4, {p,numprimes1mod4}];
}];
If[Mod[p,4] == 3,
{
numprimes3mod4 = numprimes3mod4 + 1;
primelist3mod4 = AppendTo[primelist3mod4, {p,numprimes3mod4}];
}];
primediff = AppendTo[primediff, {p, numprimes3mod4 - numprimes1mod4}];
}];
Print["Last prime calculated was ", p];
Print["Number of primes is ", numprimes];
Print["There were ", numprimes1mod4, " congruent to 1 mod 4."];
Print["There were ", numprimes3mod4, " congruent to 3 mod 4."];
];

Timing[countprimes[100000]]

ListPlot[primelist]
ListPlot[{primelist3mod4 , primelist1mod4}]
ListPlot[primediff]

Timing[countprimes[10000]]
ListPlot[primediff]