java CALOC

  • 6 Replies
  • 216 Views
*

yotamarker

  • Trusty Member
  • *********
  • Terminator
  • *
  • 769
    • battle programming
java CALOC
« on: May 20, 2020, 09:06:17 PM »
https://www.yotamarker.com/t297-java-cloc-count-active-lines-of-code-in-a-method

is there already a cleaner way to count active lines of code in a function ? this works but it is kinda crude
but it works ! with this the efficiency of a function can be measured :)
tbh ngl tbpqh tbhngl ngltbh
rabalabadabdab !!!

*

frankinstien

  • Bumblebee
  • **
  • 42
    • Knowledgeable Machines
Re: java CALOC
« Reply #1 on: May 20, 2020, 09:47:39 PM »
You might want to look at this: https://docs.microsoft.com/en-us/visualstudio/code-quality/code-metrics-values?view=vs-2019

Visual Studio does work with other languages other than .NET supported languages. But there is a listing on that page that could direct you to other types of metrics for code.

*

Don Patrick

  • Trusty Member
  • ********
  • Replicant
  • *
  • 560
    • Artificial Detective
Re: java CALOC
« Reply #2 on: May 21, 2020, 01:13:52 PM »
I am puzzled about the practical use of activated code lines as a measure of efficiency. Normally I would tally clock ticks per second if I wanted to know if a function needs optimising. A code line could contain anything from a value assignment to a function call in a loop, so there can be quite a bit of difference in their execution times.
CO2 retains heat. More CO2 in the air = hotter climate.

*

yotamarker

  • Trusty Member
  • *********
  • Terminator
  • *
  • 769
    • battle programming
Re: java CALOC
« Reply #3 on: May 21, 2020, 02:22:58 PM »
I am puzzled about the practical use of activated code lines as a measure of efficiency. Normally I would tally clock ticks per second if I wanted to know if a function needs optimising. A code line could contain anything from a value assignment to a function call in a loop, so there can be quite a bit of difference in their execution times.
that is the thing I didn't find other ways to do it.

*

Don Patrick

  • Trusty Member
  • ********
  • Replicant
  • *
  • 560
    • Artificial Detective
Re: java CALOC
« Reply #4 on: May 21, 2020, 04:51:11 PM »
I see. I'm not very familiar with Java, but some of the functions here look promising:
https://www.tutorialspoint.com/javatime/javatime_clock.htm

In C++, you'd call a clock() function at the start of the function, another one at the end, and compare the difference, like a stopwatch. Or more commonly you start a clock first, then run your function 1000x, then check the difference.
CO2 retains heat. More CO2 in the air = hotter climate.

*

frankinstien

  • Bumblebee
  • **
  • 42
    • Knowledgeable Machines
Re: java CALOC
« Reply #5 on: May 21, 2020, 05:14:05 PM »
In C++, you'd call a clock() function at the start of the function, another one at the end, and compare the difference, like a stopwatch. Or more commonly you start a clock first, then run your function 1000x, then check the difference.

What would work a bit better, and perhaps this is what you implied, set up a test rig or harness that links or references the function library(s) that you want to test, and before you call each function start a stopwatch like timer.  Collect the results and store them in a file or just output to a console or UI window.

*

yotamarker

  • Trusty Member
  • *********
  • Terminator
  • *
  • 769
    • battle programming
Re: java CALOC
« Reply #6 on: May 24, 2020, 02:34:09 AM »
I see. I'm not very familiar with Java, but some of the functions here look promising:
https://www.tutorialspoint.com/javatime/javatime_clock.htm

In C++, you'd call a clock() function at the start of the function, another one at the end, and compare the difference, like a stopwatch. Or more commonly you start a clock first, then run your function 1000x, then check the difference.

Code
package chobit;

import java.util.Calendar;
import java.util.Date;

public class TimeGate {
// a gate that only opens x minutes after it has been set
private int pause = 1;
private Date openedGate = addMinutesToJavaUtilDate(new Date(), pause);
private Date checkPoint = new Date();
public TimeGate(int minutes) {
super();
this.pause = minutes;
}
public TimeGate() {
}
public Boolean isClosed() {
return !openedGate.before(new Date());
}
public void close() {
this.openedGate = addMinutesToJavaUtilDate(new Date(), pause);
}
public void close(int minutes) {
Date now = new Date();
openedGate = addMinutesToJavaUtilDate(now, minutes);
}
private Date addMinutesToJavaUtilDate(Date date, int minutes) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.MINUTE, minutes);
    return calendar.getTime();
}
public void setPause(int pause) {
if(pause <60 && pause >0) {
this.pause = pause;}
}

public void resetCheckPoint() {
this.checkPoint = new Date();
}

public int givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen() {
Date now = new Date();
long diff = now.getTime() - this.checkPoint.getTime();
long diffSeconds = diff / 1000 % 60;
// long diffMinutes = diff / (60 * 1000) % 60;
// long diffHours = diff / (60 * 60 * 1000) % 24;
// long diffDays = diff / (24 * 60 * 60 * 1000);
// System.out.print(diffDays + " days, ");
// System.out.print(diffHours + " hours, ");
// System.out.print(diffMinutes + " minutes, ");
// System.out.print(diffSeconds + " seconds.");
return (int) diffSeconds;
}
}

use example:

Code
TimeGate timeGate = new TimeGate();
timeGate.resetCheckPoint();
for (int i = 0; i < 10000000; i++) {
System.out.println("");
}
System.out.println(timeGate.givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen());

 


Users Online

73 Guests, 0 Users

Most Online Today: 88. Most Online Ever: 340 (March 26, 2019, 09:47:57 PM)

Articles