@Test public void testLexerPerformance() throws Exception { // generate a sample JSON array StringBuilder sample = new StringBuilder(); sample.append("["); int i = 0; final int N = 5000; for (; i < N; i++) { sample.append(i); sample.append(","); } sample.append(i); sample.append("]"); String json = sample.toString(); StopWatch timer = new StopWatch(); for (int n = 0; n < 500; n++) { JSONLexer lexer = new JSONLexer(json); Token t; while ((t = lexer.nextToken()) != null) {} } _logger.info("time: " + timer.getElapsedTime()); }
public JSONToken getNextToken() { try { m_currentToken = m_lexer.yylex(); // LogManager.getInstance(JSONStreamReadContext.class).log(Level.FINE, "Token read: " + // m_currentToken); return m_currentToken; } catch (IOException ioe) { throw new ParseException(m_lexer.yytext(), m_lexer.getRow(), m_lexer.getColumn(), ioe); } }
public JSONTokenType getCurrentTokenType() { if (null == m_currentToken) { throw new ParseException( m_lexer.yytext(), m_lexer.getRow(), m_lexer.getColumn(), "Unexpected end of input stream."); } return m_currentToken.m_type; }