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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:59:54+00:00 2026-06-03T18:59:54+00:00

Why these two pieces of codes, running on same conditions, does not have difference

  • 0

Why these two pieces of codes, running on same conditions, does not have difference in amount of running time?

Code 1

static long time = 0;

static int n = 200;

static float[] vq = new float[200 * 200 * 200 * 3];
static int[] iq = new int[200 * 200 * 200];

static FloatBuffer verts = BufferUtils.createFloatBuffer(vq.length);
static IntBuffer ind = BufferUtils.createIntBuffer(iq.length);

static void draw() {

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                int index = (i * n * n) + (j * n) + k;
                vq[3 * index + 0] = i;
                vq[3 * index + 1] = j;
                vq[3 * index + 2] = k;

                iq[index] = index;
            }
        }
    }

    verts.put(vq);
    ind.put(iq);

    verts.flip();
    ind.flip();

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

    GL11.glVertexPointer(3, 0, verts);

    GL11.glDrawElements(GL11.GL_QUADS, ind);

    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

    long newTime = System.currentTimeMillis();
    System.out.println(newTime - time);
    time = newTime;
}

Code 2

static int n = 200;

static long time = 0;

static void draw() {

    GL11.glBegin(GL11.GL_QUADS);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                GL11.glVertex3f(i, j, k);
            }
        }
    }

    GL11.glEnd();

    long newTime = System.currentTimeMillis();
    System.out.println(newTime - time);
    time = newTime;
}

The reason I think Code 2 should be slower than Code1, is that it has near 8 millions native calls, but Code 1 has just a few, and they do the same thing in result.

What is the reason, and how could I improve performance of my code?

  • 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-03T18:59:57+00:00Added an answer on June 3, 2026 at 6:59 pm

    Code 1 includes copying your values into an array and then copying the array into native memory – if your n stays the same you can avoid this overhead by only doing it once.

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

Sidebar

Related Questions

What is the difference between these two pieces of code? class something { static
I have these two pieces of code. The first one works perfectly: UIView *tmp
I have these two pieces of code, wich one is more readable? foreach decimal
I have these two pieces of code that could possibly be run at the
What is the difference between these two pieces of code type IInterface1 = interface
What is the difference between these two pieces of code? TYPE t_my_cursor IS REF
Regarding class public class declaration, please look at these two pieces of code: public
Can anyone provide some clues as to why these two pieces of code are
I'm not having any errors from these pieces of code, they're just empty everytime.
I have two pieces of code that I'm using to learn about multiprocessing in

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.