java CALOC

  • 6 Replies
  • 2713 Views
*

yotamarker

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1003
  • battle programmer
    • 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

  • Replicant
  • ********
  • 642
    • 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
  • *
  • 633
    • AI / robot merchandise
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
  • **********
  • Millennium Man
  • *
  • 1003
  • battle programmer
    • 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
  • *
  • 633
    • AI / robot merchandise
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

  • Replicant
  • ********
  • 642
    • 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
  • **********
  • Millennium Man
  • *
  • 1003
  • battle programmer
    • 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());

 


OpenAI Speech-to-Speech Reasoning Demo
by ivan.moony (AI News )
Today at 01:31:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

297 Guests, 0 Users

Most Online Today: 346. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles