From b9894472c5627c9f88d0ff2b388664ee12259f94 Mon Sep 17 00:00:00 2001 From: zhumingming Date: Mon, 8 Sep 2025 06:17:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=80=E4=BA=9B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 43 +++++++++++++++++++ .../chapter2/item6/RomanNumerals.java | 2 +- src/effectivejava/chapter2/item6/Sum.java | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..c43b3684 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,43 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Adult", + "request": "launch", + "mainClass": "effectivejava.chapter2.item8.Adult", + "projectName": "effective-java-3e-source-code_616714c9" + }, + { + "type": "java", + "name": "Run RomanNumerals with args", + "request": "launch", + "mainClass": "effectivejava.chapter2.item6.RomanNumerals", + "args": [ + "5", + "1000" + ] + }, + { + "type": "java", + "name": "Run Sum with args", + "request": "launch", + "mainClass": "effectivejava.chapter2.item6.Sum", + "args": [ + "1" + ] + }, + { + "type": "java", + "name": "Run Operation with args", + "request": "launch", + "mainClass": "effectivejava.chapter7.item42.Operation", + "args": [ + "2", + "3" + ] + } +] +} + + diff --git a/src/effectivejava/chapter2/item6/RomanNumerals.java b/src/effectivejava/chapter2/item6/RomanNumerals.java index bf451409..8e0ad65c 100644 --- a/src/effectivejava/chapter2/item6/RomanNumerals.java +++ b/src/effectivejava/chapter2/item6/RomanNumerals.java @@ -26,7 +26,7 @@ public static void main(String[] args) { for (int i = 0; i < numSets; i++) { long start = System.nanoTime(); for (int j = 0; j < numReps; j++) { - b ^= isRomanNumeralSlow("MCMLXXVI"); // Change Slow to Fast to see performance difference + b ^= isRomanNumeralFast("MCMLXXVI"); // Change Slow to Fast to see performance difference } long end = System.nanoTime(); System.out.println(((end - start) / (1_000. * numReps)) + " μs."); diff --git a/src/effectivejava/chapter2/item6/Sum.java b/src/effectivejava/chapter2/item6/Sum.java index 2a7a7ebd..9fd501be 100644 --- a/src/effectivejava/chapter2/item6/Sum.java +++ b/src/effectivejava/chapter2/item6/Sum.java @@ -5,7 +5,7 @@ // Hideously slow program! Can you spot the object creation? (Page 24) public class Sum { private static long sum() { - Long sum = 0L; + long sum = 0L; for (long i = 0; i <= Integer.MAX_VALUE; i++) sum += i; return sum;