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 7875567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:00:16+00:00 2026-06-03T03:00:16+00:00

I have applied the simulated annealing algorithm (in Java) to a personal project that

  • 0

I have applied the simulated annealing algorithm (in Java) to a personal project that I am working on, but was wondering if the SA algorithm would perform slightly better on the same dataset if written in another language (i.e. C++, Python, etc).

The dummy dataset that I have created consists of five thousand users’ names, postcodes and dates of birth.

The SA algorithm is applied to the dataset in order to extract many different pieces of information.

At present, my most recent test is attempting to get the SA algorithm to detect all users whose birth dates fall within one week of each other (in any given year). Now, the SA algorithm works very well indeed; however, as I am a perfectionist, I would like to achieve slightly faster results and want to know if anybody has had any good experiences with SA producing excellent results on a similar-sized dataset, but written in other languages?

At the moment, the SA algorithm takes just under five seconds to perform a successful search.

  • 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-03T03:00:17+00:00Added an answer on June 3, 2026 at 3:00 am

    I would write it in Java

    public class UserSearchMain {
        static class Person {
            int id;
            int dateOfBirth;
    
            static Person[] generatePeople(int num) {
                Random rand = new Random();
                Person[] people = new Person[num];
                for (int i = 0; i < num; i++) {
                    Person p = new Person();
                    p.id = i;
                    p.dateOfBirth = rand.nextInt(80 * 365); // any day for 80 years.
                    people[i] = p;
                }
                return people;
            }
        }
    
        public static void main(String... args) {
            Person[] people = Person.generatePeople(5000);
            List<List<Person>> peopleByDOB = new ArrayList<List<Person>>();
            for (Person person : people) {
                int dob = person.dateOfBirth;
                while (peopleByDOB.size() <= dob) peopleByDOB.add(new ArrayList<Person>());
                peopleByDOB.get(dob).add(person);
            }
    
            Random rand = new Random();
    
            int warmup = 12 * 1000;
            int runs = 1000 * 1000;
            long start = 0;
    
            for (int i = -warmup; i < runs; i++) {
                if (i == 0) start = System.nanoTime();
                int dayToSearch = rand.nextInt(80 * 365);
                for (int j = Math.max(0, dayToSearch - 7); j <= dayToSearch + 7 && j < peopleByDOB.size(); j++) {
                    List<Person> peopleWithCloseDOM = peopleByDOB.get(j);
                }
            }
            long time = System.nanoTime() - start;
            System.out.printf("Each search took an average of %,d ns%n", time / runs);
        }
    }
    

    prints

    Each search took an average of 85 ns
    

    Often the algorithim you use is more important than the choice of language.

    EDIT: In answer to your original question, could you make this faster in C++ with the same algorithim? I would guess yes, but not by alot.


    To speed it up further you could use multiple threads.

    public static void main(String... args) throws ExecutionException, InterruptedException {
        Person[] people = Person.generatePeople(5000);
        final List<List<Person>> peopleByDOB = new ArrayList<List<Person>>();
        for (Person person : people) {
            int dob = person.dateOfBirth;
            while (peopleByDOB.size() <= dob) peopleByDOB.add(new ArrayList<Person>());
            peopleByDOB.get(dob).add(person);
        }
    
        final int runs = 10 * 1000 * 1000;
        long start = System.nanoTime();
    
        int processors = Runtime.getRuntime().availableProcessors();
        ExecutorService service = Executors.newFixedThreadPool(processors);
        List<Future> futures = new ArrayList<Future>();
        for (int i = 0; i < processors; i++) {
            futures.add(service.submit(new Runnable() {
                @Override
                public void run() {
                    Random rand = new Random();
                    for (int i = 0; i < runs; i++) {
                        int dayToSearch = rand.nextInt(80 * 365);
                        for (int j = Math.max(0, dayToSearch - 7); j <= dayToSearch + 7 && j < peopleByDOB.size(); j++) {
                            List<Person> peopleWithCloseDOM = peopleByDOB.get(j);
                        }
                    }
                }
            }));
        }
        for (Future future : futures) {
            future.get();
        }
        service.shutdown();
        double timeSec = (System.nanoTime() - start) / 1e9;
        double rate = processors * runs / timeSec / 1e6;
        System.out.printf("The search throughput was %.1f million per second%n", rate);
    }
    

    prints

    The search throughput was 32.4 million per second
    

    which implies an average of about 31 ns per search.

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

Sidebar

Related Questions

I thought this question would answer my question, but I have applied the following
I am fairly new to PHP, but have applied my previous knowledge of programming,
I have drawn a circle and applied radial gradient. fine. But when i changed
I have a web app that I've recently applied a jQuery ThemeRoller theme to.
I have HTML table in my webPage. I have applied css to that table.
I know that UIViews may transforms have applied to them , some of which
I have a form that generates divs. I have applied a base ID to
This question is a sequel to this question (I have applied the answer, but
I have a UITableViewCell that I have applied CABasicAnimation to when the user does
I have a custom control that has an Items property. I Have applied an

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.