java CALOC

  • 6 Replies
  • 3134 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
  • ********
  • 653
    • 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
  • ********
  • 653
    • 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());

 


Requirements for functional equivalence to conscious processing?
by DaltonG (General AI Discussion)
November 19, 2024, 11:56:05 am
Will LLMs ever learn what is ... is?
by HS (Future of AI)
November 10, 2024, 06:28:10 pm
Who's the AI?
by frankinstien (Future of AI)
November 04, 2024, 05:45:05 am
Project Acuitas
by WriterOfMinds (General Project Discussion)
October 27, 2024, 09:17:10 pm
Ai improving AI
by infurl (AI Programming)
October 19, 2024, 03:43:29 am
Atronach's Eye
by WriterOfMinds (Home Made Robots)
October 13, 2024, 09:52:42 pm
Running local AI models
by spydaz (AI Programming)
October 07, 2024, 09:00:53 am
Hi IM BAA---AAACK!!
by MagnusWootton (Home Made Robots)
September 16, 2024, 09:49:10 pm
LLaMA2 Meta's chatbot released
by spydaz (AI News )
August 24, 2024, 02:58:36 pm
ollama and llama3
by spydaz (AI News )
August 24, 2024, 02:55:13 pm
AI controlled F-16, for real!
by frankinstien (AI News )
June 15, 2024, 05:40:28 am
Open AI GPT-4o - audio, vision, text combined reasoning
by MikeB (AI News )
May 14, 2024, 05:46:48 am
OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00: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

Users Online

368 Guests, 0 Users

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

Articles