The scalar field theory of cosmological inflation constitutes nowadays one of the preferred scenarios for the physics of the early universe. In this paper we aim at studying the inflationary universe making use of a numerical lattice simulation. Various lattice codes have been written in the last decades and have been extensively used for understating the reheating phase of the universe, but they have never been used to study the inflationary phase itself far from the end of inflation (i.e. about 50 e-folds before the end of inflation). In this paper we use a lattice simulation to reproduce the well-known results of some simple models of single-field inflation, particularly for the scalar field perturbation. The main model that we consider is the standard slow-roll inflation with an harmonic potential for the inflaton field. We explore the technical aspects that need to be accounted for in order to reproduce with precision the nearly scale invariant power spectrum of inflaton perturbations. We also consider the case of a step potential, and show that the simulation is able to correctly reproduce the oscillatory features in the power spectrum of this model. Even if a lattice simulation is not needed in these cases, that are well within the regime of validity of linear perturbation theory, this sets the basis to future work on using lattice simulations to study more complicated models of inflation.