Understanding the impact of peers on student learning outcomes is crucial for education management. However, measuring peer effects using regression-based methods on snapshots of observational data remains a challenge. Here we develop a null-model approach to measure student peer effects using longitudinal data on the accommodation and academic performance of 5,288 undergraduates with initial random roommate assignments in China. Specifically, we build roommate null models by randomly shuffling students and propose an assimilation metric to measure differences in roommate performance. Our results show that the actual assimilation is significantly larger than the null-model assimilation, indicating significant peer effects as roommates have more similar performance than random chance. Moreover, assimilation exhibits an overall increasing trend over time, suggesting a stronger peer effect on academic performance as roommates live together longer. Regression analysis further reveals the moderating role of heterogeneous peers. When roommates have little difference in performance, the positive relationship between a focal student’s future performance and the average performance of roommates is more pronounced, and in-dorm relative ranking has an independent positive effect. Our findings provide insights into understanding the role of student roommate peers in impacting academic performance.