[JAVA] I tried to increase the processing speed with spiritual engineering


――Please do not really take this article. ――This article is an individual impression and does not show the effect or efficacy. --Complaints will only be accepted by mail.


As a service provider in the world, increasing the processing speed is a very important issue. If you simply want to increase the processing speed, you can solve it by increasing the machine power, but it is difficult to do so because it will be unprofitable as a service. Therefore, I will aim to increase the processing speed by writing the code well. In addition, this time we will use sorting, which is easy to use as an example.


We will introduce the idea of spiritual programming and aim to speed up the program.

Language selection

Select Java to take the measures described below.

Selection of sorting algorithm

If you have the idea of spiritual programming, it is obvious that any code will be explosive. The sorting algorithm uses Bogosort, which has a low best calculation time.

Measures that make you feel spiritual (including your own interpretation)

When writing a comment, enclose it in / * * / instead of //. The latter is a pair of elements, so it looks like a guardian dog and seems to be very auspicious. The semicolon (;) means "end" and is very unlucky and should be removed. Be sure to pray before you do it. Avoid annihilation.


It became a detonation velocity. (It is an individual impression.) Also, if you measure the execution time here, Never measure it as it will cause you to be suspicious of the program and cause the program to be in a bad mood and slow down. The code is below. If you can increase your spirituality, you can rewrite it more and more. (In that case, please rewrite without losing gratitude and trust in the program. It will hurt your mood.) I don't do control experiments because I trust this program.

/*The guy who wrote Bogosort, which seems to be compatible with spiritual programming, to represent the "end" and remove the unlucky semicolon*/
/*This is O(n)I feel that the probability of being able to sort by*/
/*Comment//It seems to be more auspicious by sandwiching it with paired elements instead!(Guardian dog) */
public class Bogo {
    public static void main(String... args) throws Exception {
        /*Because throws Exception doesn't work in a lambda expression*/
        for (java.util.ArrayList<Integer> data : new java.util.ArrayList[]{new java.util.ArrayList(java.util.Arrays.asList(1, 3, 2, 4, 0))}) {
            while (true) {
                /*Find out if sorted*/
                if (java.util.stream.IntStream.range(1, data.size())
                        .mapToObj(i -> data.get(i - 1) > data.get(i))
                        .noneMatch(b -> b)) {
                    /*Show if sorted*/
                    if (java.util.stream.Stream.of(
                                    .collect(java.util.stream.Collectors.joining(", "))
                            .count() == 0) {

                    if (System.class.getDeclaredMethod("exit", int.class).invoke(null, 0) == null) {
                } else {
                    /*Not sorted*/
                    if (java.util.stream.Stream.of(new java.util.Random(System.currentTimeMillis()))
                            .peek(rand -> java.util.stream.Stream.of(rand.nextInt(data.size()))
                                    .forEach(n -> java.util.stream.Stream.of(rand.nextInt(data.size()))
                                            .forEach(m -> java.util.Collections.swap(data, n, m))))
                            .count() == 0) {


Tsukkomi that seems to be common

Is Kotlin all right?




Recommended Posts

I tried to increase the processing speed with spiritual engineering
I tried to measure and compare the speed of GraalVM with JMH
I tried to interact with Java
I tried to explain the method
[Rails] I tried to implement batch processing with Rake task
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I tried to solve the problem of "multi-stage selection" with Ruby
I tried to build the environment of PlantUML Server with Docker
[Ruby] Tonight, I tried to summarize the loop processing [times, break ...]
I tried to implement the image preview function with Rails / jQuery
I tried to check the operation of gRPC server with grpcurl
I tried migrating Processing to VS Code
I tried to get started with WebAssembly
I tried to implement the Iterator pattern
I tried to summarize the Stream API
I tried to implement ModanShogi with Kinx
[iOS] I tried to make a processing application like Instagram with Swift
[Ruby] I tried to diet the if statement code with the ternary operator
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I tried to make Basic authentication with Java
I tried to manage struts configuration with Coggle
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to manage login information with JMX
I tried to organize the session in Rails
I tried to set tomcat to run the Servlet.
I tried to break a block with java (1)
I want to perform aggregation processing with spring-batch
I tried to compare the infrastructure technology of engineers these days with cooking.
I tried to get the distance from the address string to the nearest station with ruby
I tried to organize the cases used in programming
I tried to read and output CSV with Outsystems
I tried to implement TCP / IP + BIO with JAVA
[Java 11] I tried to execute Java without compiling with javac
I tried to summarize the state transition of docker
I tried to decorate the simple calendar a little
[Rails] I tried playing with the comment send button
05. I tried to stub the source of Spring Boot
I started MySQL 5.7 with docker-compose and tried to connect
I tried to reduce the capacity of Spring Boot
I tried to get started with Spring Data JPA
I want to dark mode with the SWT app
I tried to draw animation with Blazor + canvas API
I tried OCR processing a PDF file with Java
I tried to implement Stalin sort with Java Collector
I tried to implement the Euclidean algorithm in Java
roman numerals (I tried to simplify it with hash)
I tried to check the operation of http request (Put) with Talented API Tester
[Beginner's point of view] I tried to solve the FizzBuzz problem "easily" with Ruby!
I tried to summarize the points to consider when acquiring location information with the iOS application ①
I tried to summarize the points to consider when acquiring location information with the iOS application ②
I tried to investigate the mechanism of Emscripten by using it with the Sudoku solver
I tried to implement the like function by asynchronous communication
I tried to make an introduction to PHP + MySQL with Docker
I tried to create a java8 development environment with Chocolatey
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
I tried to modernize a Java EE application with OpenShift.
I tried DI with Ruby
[JDBC] I tried to access the SQLite3 database from Java.
I tried to summarize the basics of kotlin and java