Almost certainly the first exam system for which students crammed was the Imperial Chinese examination system, which was in existence by the time of the foundation of the Han dynasty, formalised by around 100 BCE, developed into tests of individual merit under the Tang, and greatly expanded under the Sung as a means of countering the influence of warlord families, during which period some 79,000 scholars attempted the exams each year, and about half the members of the imperial bureaucracy were successful examination candidates (see Patricia Buckley Ebrey, Confucianism and Family Rituals in Imperial China pp.45-6). Success thus opened the doors to prestigious jobs in the imperial bureaucracy, more or less guaranteeing not only a comfortable living but also the strong possibility of significant professional and social elevation for the candidate's family across several generations.(Ebrey gives the example of Ssu-ma Kuang (1019-1086), a successful exam candidate who was followed into the imperial service by 23 relations.)
These exams required memorisation of huge quantities of classical text. Ichisada Miyazaki, in his tellingly-titled China's Examination Hell: The Civil Service Examinations of Imperial China, notes the sheer quantity of rote learning required from candidates. General classical education began at the age of 8 and extended to the age of 15; during this time, students were expected to learn by heart a total of 431,286 characters derived from the works of Confucius, Mencius, the Book of Changes, the Book of Documents and three other titles. Exams consisted in large part of filling in the blanks in extracts drawn from these works. On top of that, candidates were expected to have digested commentaries several times the length of the original works, and sufficient purely literary works to be able to write essays and poetry modelled on them.
In the west, a relatively early example of extreme exam cramming can be found at the University of Cambridge, which was in the 19th century one of the world's leading centres for the study of mathematics. Cambridge evolved a system under which all students had to study maths for the first two years of their degree, and all candidates were ranked numerically (rather than broadly by degree class); this made it possible for one student each year to be identified as the best mathematician in the university, and significantly increased competition. As was the case in China, the top candidates in the maths exams were all but guaranteed academic posts on graduation, further increasing the competitiveness of the tests. Men taking “first class” degrees—equivalent to the American summa cum laude–became Wranglers; those placed below them in the second class–magna cum laude–were Optimes. The man who emerged top of the pile was named "Senior Wrangler", and guaranteed a significant degree of academic fame.
Candidates typically sat for five and a half hours of exams every day for eight days—12 papers and 192 progressively more difficult questions in all. Those in contention for the title of Wrangler then sat for a further three days of examinations consisting of 63 still more testing problems. The most serious candidates invariably hired tutors and worked more or less round the clock for months. The historian Alex Craik (in his Mr Hopkins’s Men: Cambridge Reform and British Mathematics in the Nineteenth Century) notes that C.T. Simpson, who ranked as Second Wrangler in 1841, topped off his efforts by studying for 20 hours a day in the week before the exams and “almost broke down from over-exertion… found himself actually obliged to carry a supply of ether and other stimulants into the examinations in case of accidents.” James Wilson, who topped the rankings in 1859, had a nervous breakdown immediately after his exams; on his recovery he discovered he had forgotten all the maths he ever knew except elementary algebra. And James Savage worked himself so hard that he was found dead of apoplexy in a ditch three months after being named Senior Wrangler of 1855.
Incidentally, the only woman ever to top the Cambridge mathematical rankings was Philippa Fawcett, in 1890, and she did it without indulging in the sort of extreme cramming mentioned above. I wrote about her remarkable and inspirational story here:
https://mikedashhistory.com/2011/10/31/above-the-senior-wrangler/