Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:20:58+00:00 2026-06-17T07:20:58+00:00

I’m new in D and I’m comparing it vs Java in simple tests and

  • 0

I’m new in D and I’m comparing it vs Java in simple tests and expecting to see that the native language will be faster (or roughly the same). But it in my first test with recursion D is surprisingly slower than Java (almost two times).

Java (this is bad java perfomance test but it just simple idea):

public static void main(String... args) {
        long before = System.nanoTime();
        System.out.println(fibonacci(40));
        System.out.println(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - before));
    }

    static int fibonacci(int n) {
        if (n < 2) {
            return n;
        }
        return fibonacci(n - 2) + fibonacci(n - 1);
    }

Environment: Win7 64bit, JDK: 1.7.0_10 x64.

D:

import std.stdio;
import std.datetime;

void main(string[] args)
{
    auto r = benchmark!(simplebench)(1);
    writefln("%s", r[0].to!("msecs", int));
}

void simplebench() {
    writeln(fibonacci(40));
}

int fibonacci(int n) {
    if (n < 2) {
        return n;
    }
    return fibonacci(n - 2) + fibonacci(n - 1);
}

Environment: Win7 64bit, dmd 2.061, compiler options: -noboundscheck -inline -O -release

Java ~570ms and D ~1011ms.

What am I doing wrong?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:20:59+00:00Added an answer on June 17, 2026 at 7:20 am

    Java is also native via its JIT compiler. If you disable the JIT using -Xint (forces interpreter) then you’ll see that D is significantly faster. For what it’s worth, I tried a similar implementation in C and got the same speed as in D.

    These sorts of micro benchmarks are not useful for testing general performance. All you are doing here is testing Java JIT compiled code versus D compiled code. They’re both being compiled. Also, this is not typical Java code. Typical Java programs allocates a lot of memory on the heap, whereas typical D programs do not.

    If you want to learn about real performance of D versus Java then you need you test it on real programs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.