The key novelty of this contribution is a dedicated technique to e fficiently determine the distance (gap) function between parallel or almost parallel beams with circular and elliptical cross-sections. The technique consists of parametrizing the surfaces of the two beams in contact, fixing a point on the centroid line of one of the beams and searching for a constrained minimum distance between the surfaces (two variants are investigated). The resulting unilateral (frictionless) contact condition is then enforced with the Penalty method, which introduces compliance to the, otherwise rigid, beams' cross-sections. Two contact integration schemes are considered: the conventional slave-master approach (which is biased as the contact virtual work is only integrated over the slave surface) and the so-called two-half-pass approach (which is unbiased as the contact virtual work is integrated over the two contacting surfaces). Details of the finite element formulation which is suitably implemented using Automatic Di fferentiation techniques are presented. A set of numerical experiments shows the overall performance of the framework and allows a quantitative comparison of the investigated variants