One method works too slowly (about 1.5 seconds, the text length is 460 characters; you need as little as possible). It is quite possible as a result of the error in the code. Can code with such functionality work faster?

public static double calcIndexTrigrams(String str) throws IOException { int nG=3; double index = 0; File file = new File(TRIGRAMS); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_16)); String line; for (int c = 0; c < (str.length()-nG); c++) { reader.mark((int) file.length()); while((line = reader.readLine())!= null){ if (str.substring(c,c+nG).equalsIgnoreCase(line.substring(0,nG))) { index+=(Double.parseDouble(line.substring(nG+1))); break;}} reader.reset();} return index;} 
  • one
    First, it is better to show a complete example. Secondly, it is necessary to define what is "prohibitively long" and how much ideally it should work. - KoVadim
  • Well, what is the cryptography algorithm? Perhaps this is the reason. - Kostya Bakay
  • @kovadim thanks, fixed the question. - Antolian Sontar
  • The first thing I would do is unwrap the cycles. The file cycle should be first, and the line cycle should be inside. - KoVadim 4:03

0