All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dakusui.lisj.forms.specials.Time Maven / Gradle / Ivy

package com.github.dakusui.lisj.forms.specials;

import com.github.dakusui.lisj.core.Context;
import com.github.dakusui.lisj.core.Kernel;
import com.github.dakusui.lisj.forms.Form;

/**
 * Returns time to execute a given S-expression in msec.
 */
public class Time extends Form.Base {

  @Override public Result applyForm(Context context, Object args) {
    long before = System.currentTimeMillis();
    int len = Kernel.KERNEL.$length(args);
    Object[] results = new Object[len];
    for (int i = 0; i < len; i++) {
      Result cur;
      cur = applyEach(context, Kernel.KERNEL.$get(args, i), Result.Type.Next, Result.Type.Throw);
      if (cur.type == Result.Type.Throw) return cur;
      results[i] = cur.value;
    }
    return new Result(Kernel.KERNEL.$cons(System.currentTimeMillis() - before, results));

  }

  @Override
  public Object checkArgs(Object args) {
    return args;
  }

  @Override
  public Object checkParams(Object params) {
    return params;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy