Package net.algart.arrays

Examples of net.algart.arrays.MutableCharArray


        for (int doEnsureCapacity = 0; doEnsureCapacity < 2; doEnsureCapacity++) {
            System.out.println("Tests with" + (doEnsureCapacity == 0 ? "out" : "") + " ensureCapacity()");
            for (int count = 1; count <= 10; count++) {
                System.out.println("Iteration #" + count);
                long t1 = System.nanoTime();
                MutableCharArray cv = Arrays.SystemSettings.globalMemoryModel().newEmptyCharArray();
                if (doEnsureCapacity > 0)
                    cv.ensureCapacity(n * w.length());
                for (int k = 0; k < n; k++)
                    cv.append(w);
                long t11 = System.nanoTime();
                String s1 = Arrays.asCharSequence(cv).toString();
                long t2 = System.nanoTime();

                StringBuffer sbuf = new StringBuffer();
                if (doEnsureCapacity > 0)
                    sbuf.ensureCapacity(n * w.length());
                for (int k = 0; k < n; k++)
                    sbuf.append(w);
                long t21 = System.nanoTime();
                String s2 = sbuf.toString();
                long t3 = System.nanoTime();

                StringBuilder sb = new StringBuilder();
                if (doEnsureCapacity > 0)
                    sb.ensureCapacity(n * w.length());
                for (int k = 0; k < n; k++)
                    sb.append(w);
                long t31 = System.nanoTime();
                String s3 = sb.toString();
                long t4 = System.nanoTime();

                System.out.printf(Locale.US,
                    "CharArray.appendString + toString: %.6f+%.6f ms, %.3f ns/word (%d chars)%n",
                    (t11 - t1) * 1e-6(t2 - t11) * 1e-6, (t2 - t1) * 1.0 / n,  cv.length());
                System.out.printf("    '" + (s1.length() < 100 ? s1 : s1.substring(0, 100) + "...") + "'%n");

                System.out.printf(Locale.US,
                    "StringBuffer.append + toString:     %.6f+%.6f ms, %.3f ns/word%n",
                    (t21 - t2) * 1e-6, (t3 - t21) * 1e-6, (t3 - t2) * 1.0 / n);
View Full Code Here

TOP

Related Classes of net.algart.arrays.MutableCharArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.