Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: O(1) Listener add/delete #562

Merged
merged 1 commit into from
Jul 17, 2019
Merged

Conversation

morris821028
Copy link
Contributor

This is a simple test case for performance turning.

The origin type Vector will use O(n) time on removeElement.

package bsh;

import java.util.Scanner;

public class PerformanceStateTest {
	public static String getName(String s) {
		return s + "A";
	}
	
	public static void main(String[] args) {
		final Interpreter interpreter = new Interpreter();

		Runtime runtime = Runtime.getRuntime();

		long usedMemoryBefore = 0;
		long usedMemoryAfter = 0;
		long start;
		long end;
		
		Scanner cin = new Scanner(System.in);
//		
		cin.next();
		
		try {
			interpreter.eval("import bsh.PerformanceStateTest;");
			interpreter.eval("a = \"1\" + \"2\";");
			interpreter.eval("String getName(String s) { return \"\" + PerformanceStateTest.getName(s); }");
			interpreter.eval("String getName2(String s) { if (s.charAt(0) == '1') return s + \"B\"; }");
			interpreter.eval("b = \"3\" + \"4\";");
		} catch (EvalError e) {
			e.printStackTrace();
		}
		
		start = System.currentTimeMillis();
		try {
			String v = null;
			for (int i = 0; i < 500000; i++) {
				v = (String) interpreter.eval("getName(\"123\")");
			}
			System.out.println(v);
		} catch (EvalError e) {
			e.printStackTrace();
		}
		end = System.currentTimeMillis();
		final long goldTime = end - start;
		System.out.printf("time %d", goldTime);
	}
}

@codecov
Copy link

codecov bot commented Jul 14, 2019

Codecov Report

Merging #562 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #562      +/-   ##
============================================
- Coverage     71.06%   71.05%   -0.01%     
  Complexity     2723     2723              
============================================
  Files           106      106              
  Lines          8912     8911       -1     
  Branches       1745     1745              
============================================
- Hits           6333     6332       -1     
  Misses         2174     2174              
  Partials        405      405
Impacted Files Coverage Δ Complexity Δ
src/main/java/bsh/classpath/ClassManagerImpl.java 64.67% <100%> (-0.22%) 39 <8> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 542bd0e...0ae2c1c. Read the comment docs.

@nickl- nickl- merged commit 800e6c0 into beanshell:master Jul 17, 2019
@nickl-
Copy link
Member

nickl- commented Jul 17, 2019

@morris821028 Nice 1 Thanx

pgiffuni pushed a commit to pgiffuni/beanshell that referenced this pull request Jan 8, 2024
Performance: O(1) Listener add/delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants