⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_java.html

📁 JNI(java本地接口)之delphi版
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);


      <font color="#003399"><i>// Call a Native 'void func(void)'</i></font>
    System.out.print(<font color="#9933CC">&quot;Native function calls &quot;</font> + func_calls + <font color="#9933CC">&quot; ....&quot;</font>);
    start = System.currentTimeMillis();
    <b>for</b> (x = 0; x &lt; func_calls; x++)
      nat.VoidVoid();
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);

      <font color="#003399"><i>// Call a Java method 'void method(void)'</i></font>
    System.out.print(<font color="#9933CC">&quot;  Java function calls &quot;</font> + func_calls + <font color="#9933CC">&quot; ....&quot;</font>);
    start = System.currentTimeMillis();
    <b>for</b> (x = 0; x &lt; func_calls; x++)
      VoidVoid();
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);

    t = 1000;

      <font color="#003399"><i>// Call Native code to initialize an array to a specific value many times</i></font>
    System.out.print(<font color="#9933CC">&quot;Native initialize array[&quot;</font> + array_size + <font color="#9933CC">&quot;] &quot;</font> + t + <font color="#9933CC">&quot; times ....&quot;</font>);
    start = System.currentTimeMillis();
    nat.initializeByteArray(d, t, value);
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);


      <font color="#003399"><i>// Initialize an array to a specific value many times within Java</i></font>
    System.out.print(<font color="#9933CC">&quot;  Java initialize array[&quot;</font> + array_size + <font color="#9933CC">&quot;] &quot;</font> + t + <font color="#9933CC">&quot; times ....&quot;</font>);
    start = System.currentTimeMillis();
    <b>for</b> (<b>int</b> i = 0; i &lt; t; i++)
      <b>for</b> (<b>int</b> j = 0; j &lt; d.length; j++)
        d[j] = value;
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);

      <font color="#003399"><i>// From native code, call a constructor for a Java object many times</i></font>
    java.awt.Rectangle[] rects4 = <b>new</b> java.awt.Rectangle[rectangles];
    <b>for</b> (<b>int</b> i = 0; i &lt; rects4.length; i++)
      rects4[i] = <b>new</b> java.awt.Rectangle(0, 0, 4 * i, 3 * i);
    System.out.print(<font color="#9933CC">&quot;Native callbacks into Java constructor &quot;</font> + rectangles + <font color="#9933CC">&quot; rectangles ....&quot;</font>);
    start = System.currentTimeMillis();
    nat.printObjectArray(rects4, <b>false</b>);
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);

      <font color="#003399"><i>// Call a constructor from Java many times</i></font>
    java.awt.Rectangle[] rects5 = <b>new</b> java.awt.Rectangle[rectangles];
    <b>for</b> (<b>int</b> i = 0; i &lt; rects5.length; i++)
      rects5[i] = <b>new</b> java.awt.Rectangle(0, 0, 4 * i, 3 * i);
    System.out.print(<font color="#9933CC">&quot;Java method calls to constructor &quot;</font> + rectangles + <font color="#9933CC">&quot; rectangles ....&quot;</font>);
    start = System.currentTimeMillis();
    printObjectArray(rects5, <b>false</b>);
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);

      <font color="#003399"><i>// Call a Java 'void method(void)' from Native code many times</i></font>
    System.out.print(<font color="#9933CC">&quot;Native callbacks to Java void method &quot;</font> + func_calls + <font color="#9933CC">&quot; ....&quot;</font>);
    start = System.currentTimeMillis();
    nat.callbackVoid(func_calls);
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);

      <font color="#003399"><i>// Call a Native 'void func(void)' from Java many times</i></font>
    System.out.print(<font color="#9933CC">&quot;Java calls to Native void function &quot;</font> + func_calls + <font color="#9933CC">&quot; ....&quot;</font>);
    start = System.currentTimeMillis();
    <b>for</b> (x = 0; x &lt; func_calls; x++)
      nat.VoidVoid();
    stop = System.currentTimeMillis();
    elapsed = stop - start;
    System.out.println(<font color="#9933CC">&quot; &quot;</font> + elapsed + <font color="#9933CC">&quot; milliseconds&quot;</font>);

  }

    <font color="#003399"><i>// Test method for function-call overhead</i></font>
  <b>public</b> <b>static</b> <b>void</b> VoidVoid()
  {
    <b>return</b>;
  }

    <font color="#003399"><i>// Sieving prime numbers</i></font>
  <b>public</b> <b>static</b> <b>long</b> countPrimes(<b>byte</b>[] array)
  {
    <b>int</b> count = 0;
    <b>int</b> i;

    <b>for</b> (i = 0; i &lt; array.length; i++)
      array[i] = 1;

    <b>for</b> (i = 2; i &lt; array.length; i++)
    {
      <b>if</b> (array[i] != 0)
      {
        <b>int</b> k;
        <b>for</b> (k = i + i; k &lt; array.length; k += i)
          array[k] = 0;

        count++;
      }
    }

    <b>return</b> count;
  }

  <b>public</b> <b>static</b> java.awt.Rectangle[] returnRectArray(<b>int</b> size)
  {
      <font color="#003399"><i>// Allocate the array of Rectangles</i></font>
    java.awt.Rectangle[] array = <b>new</b> java.awt.Rectangle[size];

      <font color="#003399"><i>// Now initialize each one to a Rectangle</i></font>
    <b>for</b> (<b>int</b> i = 0; i &lt; size; i++)
    {
        <font color="#003399"><i>// Create a new Rectangle object</i></font>
      java.awt.Rectangle element = <b>new</b> java.awt.Rectangle(0, 0, 5 * i, 10 * i);

        <font color="#003399"><i>// Assign the Rectangle to an element of the array</i></font>
      array[i] = element;
    }
      <font color="#003399"><i>// Return whole array to caller</i></font>
    <b>return</b> array;
  }


  <b>public</b> <b>static</b> <b>void</b> printObjectArray(Object[] objArray, <b>boolean</b> Print)
  {
      <font color="#003399"><i>// Loop the the array of objects and print out each one using</i></font>
      <font color="#003399"><i>// the 'toString' method of its ancestor class Object</i></font>
    <b>for</b> (<b>int</b> i = 0; i &lt; objArray.length; i++)
    {
      String s = objArray[i].toString();
      <b>if</b> (Print)
        System.out.println(s);

   }
  }

}
</code></pre>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -