Evaluating LLMs for Code Generation: HumanEval Benchmarking

March 30, 2025 | Tags: LLMs Code Generation HumanEval Benchmarking

As Large Language Models continue to evolve, evaluating their capabilities for code generation becomes increasingly important for researchers and practitioners. In this blog post, I explore how several popular open-source LLMs perform on the HumanEval benchmark in a zero-shot setting.

Understanding the HumanEval Benchmark

HumanEval is a widely used benchmark for evaluating code generation capabilities of language models. Introduced by OpenAI, it consists of 164 hand-written programming problems that test various aspects of coding ability. Each problem includes:

  • A function signature
  • A docstring describing the function's purpose
  • Example test cases
  • Hidden test cases for evaluation

The primary metric used in HumanEval is Pass@k, which measures the probability that at least one correct solution appears among k generated samples. In this evaluation, I focus specifically on Pass@1, which represents the model's ability to generate a correct solution on the first attempt.

Models Evaluated

I evaluated five popular open-source LLMs that have shown promising results for code generation:

  • Mistral 7B - A powerful 7B parameter model known for efficient performance
  • Llama 3.1 8B - Meta's 8B parameter model with improved reasoning capabilities
  • Llama 3.2 3B - A smaller but highly efficient version from Meta's latest series
  • CodeLlama 7B - Specifically fine-tuned for code generation tasks
  • CodeLlama 13B - Larger variant with enhanced coding capabilities

Methodology

All evaluations were conducted using a zero-shot approach, where the models receive only the function signature and docstring without any examples or additional context. For each problem, the models generate a single solution (for Pass@1 evaluation) using greedy decoding with a maximum token length of 512.

Performance metrics collected include:

  • Pass@1 - Percentage of problems solved correctly on the first attempt
  • Samples/sec - How many complete solutions the model can generate per second
  • Tokens/sec - The number of tokens generated per second

All evaluations were run on a single NVIDIA A100 GPU to ensure consistency in performance measurement.

Results

The table below summarizes the performance of each model across our evaluation metrics:

Model Parameters Pass@1 (%) Total Gen. Tokens Samples/sec Tokens/sec
Mistral 7B 7B 39.02% 46,399 5.04 1,427.27
Llama 3.2 3B 3B 42.07% 159,905 2.68 2,613.00
Llama 3.1 8B 8B 56.10% 148,293 2.00 1,811.15
CodeLlama 7B 7B 38.41% 50,989 3.70 1,149.21
CodeLlama 13B 13B 41.46% 18,617 3.85 436.57
Note: All evaluations were conducted with temperature=0.2, top-k=50, top-p=0.95, and max tokens=1024 on identical hardware.

Key Insights

Performance Highlights

  • Highest Accuracy: Llama 3.1 8B achieves the best Pass@1 score (56.10%), significantly outperforming all other models including larger ones like CodeLlama 13B.
  • Fastest Completion: Mistral 7B generates complete solutions most rapidly at 5.04 samples/sec, making it ideal for scenarios requiring quick responses.
  • Highest Token Generation Speed: Llama 3.2 3B produces tokens at an impressive 2,613.00 tokens/sec, despite being the smallest model tested.
  • Best Performance Tradeoff: Mistral 7B offers an excellent balance between accuracy (39.02% Pass@1) and speed (5.04 samples/sec), making it suitable for real-time applications where both factors matter.

Analysis

Surprising Performance of Llama 3.1 8B

Perhaps the most unexpected finding is that Llama 3.1 8B significantly outperforms all other models in Pass@1 accuracy with 56.10%, even surpassing the larger CodeLlama 13B model that was specifically fine-tuned for code generation. This suggests that recent improvements in base model architectures may be more impactful than specialized fine-tuning for certain tasks.

Efficiency vs. Size

Llama 3.2 3B demonstrates remarkable token generation efficiency (2,613.00 tokens/sec) despite being the smallest model evaluated. However, this speed doesn't translate directly to samples/sec, suggesting it generates more tokens per solution than other models. This efficiency-accuracy balance makes it an interesting option for edge deployment scenarios.

CodeLlama Performance

Surprisingly, the CodeLlama models underperform their general-purpose counterparts despite being specifically fine-tuned for code generation. CodeLlama 7B achieves the lowest Pass@1 score (38.41%), while CodeLlama 13B (41.46%) falls short of both Llama models. This raises questions about the effectiveness of domain-specific fine-tuning compared to advancements in base model architecture.

Conclusion

The evaluation reveals interesting trade-offs between model size, specialization, and efficiency. While CodeLlama 13B achieves the best absolute performance, the efficiency of smaller models like Llama 3.2 3B makes them attractive options for resource-constrained environments or applications requiring real-time code generation.

As open-source LLMs continue to improve, we can expect the gap between specialized and general models to narrow further, potentially enabling more powerful code generation capabilities in smaller, more efficient packages.

In future work, I plan to extend this evaluation to include additional metrics such as Pass@10 and Pass@100, as well as explore few-shot prompting approaches to see how these models perform when provided with examples.