Skip to content

Instantly share code, notes, and snippets.

@jwhite66
Created March 14, 2019 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwhite66/c799cc8bca57f165d5d70907749fd9bc to your computer and use it in GitHub Desktop.
Save jwhite66/c799cc8bca57f165d5d70907749fd9bc to your computer and use it in GitHub Desktop.
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends TimedRobot {
private double freememory = 0.0;
private double m_a = 1.0;
private double m_b = 2.0;
private double m_c = 3.0;
private double m_d = 4.0;
private double m_e = 5.0;
private double m_f = 6.0;
private double m_g = 7.0;
private double m_h = 8.0;
private double m_i = 9.0;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
double start = Timer.getFPGATimestamp();
String fred;
fred = "Slow me down" +
", m_a: " + m_a +
", m_b: " + m_b +
", m_b: " + m_c +
", m_b: " + m_d +
", m_b: " + m_e +
", m_b: " + m_f +
", m_b: " + m_g +
", m_b: " + m_h +
", m_b: " + m_i;
System.out.println(fred);
System.out.println("Normal string operations took: " + (Timer.getFPGATimestamp() - start));
start = Timer.getFPGATimestamp();
StringBuilder joe = new StringBuilder(256);
joe.append("Don't slow me down");
joe.append(", m_a: ").append(m_a);
joe.append(", m_b: ").append(m_b);
joe.append(", m_c: ").append(m_c);
joe.append(", m_d: ").append(m_d);
joe.append(", m_e: ").append(m_e);
joe.append(", m_f: ").append(m_f);
joe.append(", m_g: ").append(m_g);
joe.append(", m_h: ").append(m_h);
joe.append(", m_i: ").append(m_i);
System.out.println(joe.toString());
System.out.println("String builder operations took: " + (Timer.getFPGATimestamp() - start));
}
/**
* This function is called periodically during operator control.
*
*/
@Override
public void robotPeriodic() {
if (freememory == 0.0 || freememory > Runtime.getRuntime().freeMemory()) {
freememory = Runtime.getRuntime().freeMemory();
System.out.println(Timer.getFPGATimestamp() + ": new low mem " + freememory);
}
if (freememory != 0.0 && Runtime.getRuntime().freeMemory() > freememory) {
freememory = Runtime.getRuntime().freeMemory();
System.out.println(Timer.getFPGATimestamp() + ": garbage went out " + freememory);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment