Which code is faster?

int i=0;

glBegin(GL_POINTS);
for(i=0;i<numOfVertex;i++){
glVertex3fv(&poly[i].x);
}
glEnd();
for(i=0;i<numOfVertex-1;i++){
glBegin(GL_LINES);
glVertex3fv(&poly[i].x);
glVertex3fv(&poly[i+1].x);
glEnd();
}

for(i=0;i<numOfVertex-1;i++){
glBegin(GL_POINTS);
glVertex3fv(&poly[i].x);
glEnd();

glBegin(GL_LINES);
glVertex3fv(&poly[i].x);
glVertex3fv(&poly[i+1].x);
glEnd();
}
glBegin(GL_POINTS);
glVertex3fv(&poly[i].x);
glEnd();

At first i taught the 2nd one should be faster because only one loop. But when i try both of the code, the first one can render faster than the 2nd one. Does anyone know the reason?

the first code is faster because you call glBegin(…)/glEnd() less than in the second one.

note that this code is faster:

glBegin(GL_POINTS);
for(i=0;i<numOfVertex;i++)
{
glVertex3fv(&poly[i].x);
}
glEnd();
glBegin(GL_LINE_STRIP);
for(i=0;i<numOfVertex;i++)
{
glVertex3fv(&poly[i].x);
}
glEnd();